What does python return on the leap second
<p>What does python <code>time</code> and <code>datetime</code> module return on the leap second?</p>

<p>What will I get when we are at <em>23:59:60.5</em> if I call:</p>

<ul>
<li><code>time.time()</code></li>
<li><code>datetime.datetime.utcnow()</code></li>
<li><code>datetime.datetime.now(pytz.utc)</code></li>
</ul>

<p>Also, any difference between py2.7 and py3?</p>

<hr>

<p>Why it is confusing (at least for me):</p>

<p>From the <a href="https://docs.python.org/2/library/datetime.html" rel="nofollow">datetime docs</a> I see:</p>

<blockquote>
  <p>Unlike the time module, the datetime module does not support leap seconds.</p>
</blockquote>

<p>On the <a href="https://docs.python.org/2/library/time.html#module-time" rel="nofollow">time docs</a> I see there is "support" for leap seconds when parsing with <code>strptime</code>. But there is no comment about <code>time.time()</code>.</p>

<p>I see that using <code>time</code> I get:</p>

<pre><code>&gt;&gt;&gt; time.mktime(time.strptime('2016-06-30T23:59:59', "%Y-%m-%dT%H:%M:%S"))
1467327599.0
&gt;&gt;&gt; time.mktime(time.strptime('2016-06-30T23:59:60', "%Y-%m-%dT%H:%M:%S"))
1467327600.0
&gt;&gt;&gt; time.mktime(time.strptime('2016-07-01T00:00:00', "%Y-%m-%dT%H:%M:%S"))
1467327600.0
</code></pre>

<p>And <code>datetime</code> just blows up:</p>

<pre><code>&gt;&gt;&gt; dt.datetime.strptime('2016-06-30T23:59:60', "%Y-%m-%dT%H:%M:%S")
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &amp;lt;module&gt;
ValueError: second must be in 0..59
</code></pre>

<p>Then what will I get at that exact time (in the middle of the leap second)?</p>

<p>I have read about rubber times, clocks slowing down, repeating seconds, and all kind of crazy ideas, but what should I expect on python?</p>

<p>Note: In case you wonder if I don't have anything better to do that care about it, a leap second is approaching!!!!</p>

<p>Leap seconds are occasionally <em>manually</em> scheduled. Currently, computer clocks have no facility to honour leap seconds; there is no standard to tell them up-front to insert one. Instead, computer clocks periodically re-synch their time keeping via the NTP protocol and adjust automatically after the leap second has been inserted.</p>

<p>Next, computer clocks usually report the time as <em>seconds since the epoch</em>. It'd be up to the <code>datetime</code> module to adjust its accounting when converting that second count to include leap seconds. It doesn't do this at present. <code>time.time()</code> will just report a time count based on the seconds-since-the-epoch.</p>

<p>So, <em>nothing different</em> will happen when the leap second is officially in effect, other than that your computer clock will be 1 second of for a little while.</p>

<p>The issues with <code>datetime</code> only cover <em>representing</em> a leap second timestamp, which it can't. It won't be asked to do so anyway.</p>

python datetime time leap-second