title: What do Unix timestamps actually track?
body: <p>I know that the Unix timestamp is defined as the number of seconds passed since <code>1970-01-01 00:00:00Z</code>. However, I could not find a clear source that gives this definition. I've also read various different statements about the relationship between UTC and the Unix Timestamp in regards to leap seconds.</p>
  <p><a href="https://en.wikipedia.org/wiki/Leap_second" rel="nofollow noreferrer">This wikipedia page</a> contains a list of all leap seconds. The first one is</p>
  <pre><code>1972-06-30 23:59:60
  </code></pre>
  <h2>Statements about Unix timestamps</h2>
  <blockquote>
  <p>As for &quot;all modern computer systems&quot;, Unix time is completely ignorant about anything except seconds.</p>
  </blockquote>
  <p>Source: <a href="https://news.ycombinator.com/item?id=4128613" rel="nofollow noreferrer">HackerNews, brazzy</a></p>
  <blockquote>
  <p>UNIX time tracks UTC instead of TAI meaning it &quot;corrects&quot; for leap seconds. As a result, UNIX time is not &quot;the number of seconds since epoch&quot; but &quot;86400 * (number of whole days since epoch) + (number of seconds since midnight)&quot;, and UNIX time will go forwards (never so far) and backwards on leap seconds (a second will repeat in most implementations as the day goes from 23:59:60 to 00:00:00, as they have the same timestamp).</p>
  </blockquote>
  <p>Source: <a href="https://news.ycombinator.com/item?id=4130447" rel="nofollow noreferrer">Hacker News, masklinn</a></p>
  <p>I've also read (but I can't find it again - somewhere on Stack Overflow) that Unix Timestamps assume each day has exactly 24*60*60 seconds. The poster implied that days are still somehow kept synchronously while the leap seconds simply &quot;slows down&quot; the real second. Hence a &quot;unix timestamp second&quot; might not be a SI second.</p>
  <h2>Possible answers</h2>
  <p>I can see three possible answers:</p>
  <p>A1: Unix Timestamps track SI seconds since 1970-01-01 00:00:00Z. This means they are 27 seconds off from the UTC.</p>
  <p>A2: Unix Timestamps track &quot;passed seconds in TAI&quot;. This means a library that converts Unix timestamps to UTC has to deal with leap seconds.</p>
  <p>A3: Unix Timestamps track &quot;passed seconds in UTC&quot;. This means that a difference between two Unix timestamps of 1 might be 1 SI-second in most cases, but not in all.</p>
  <p>Please add a source to your answer.</p>
  <h2>Python</h2>
  <p>Pythons <code>datetime</code> seems not to be aware of leap seconds (?).</p>
  <pre><code>&gt;&gt;&gt; import datetime
  &gt;&gt;&gt; a = datetime.datetime(1972, 6, 30, 23, 59, 59)
  &gt;&gt;&gt; b = datetime.datetime(1972, 7, 1, 0, 0, 0)
  &gt;&gt;&gt; b-a
  datetime.timedelta(0, 1)
  </code></pre>
  <p>and the <code>time</code> module seems to map the actual leap second on the second before:</p>
  <pre><code>&gt;&gt;&gt; import time
  &gt;&gt;&gt; t3 = time.mktime((1972, 6, 30, 23, 59, 59, -1, -1, -1))
  &gt;&gt;&gt; t4 = time.mktime((1972, 7, 1, 0, 0, 0, -1, -1, -1))
  &gt;&gt;&gt; t4 - t3
  1.0
  &gt;&gt;&gt; t4 = time.mktime((1972, 6, 30, 23, 59, 60, -1, -1, -1))
  &gt;&gt;&gt; t4 - t3
  1.0
  </code></pre>
  <p>This impression is supported by <a href="https://bugs.python.org/issue23574" rel="nofollow noreferrer">issue23574</a>.</p>