What does python time
and datetime
module return on the leap second?
What will I get when we are at 23:59:60.5 if I call:
time.time()
datetime.datetime.utcnow()
datetime.datetime.now(pytz.utc)
Also, any difference between py2.7 and py3?
Why it is confusing (at least for me):
From the datetime docs I see:
Unlike the time module, the datetime module does not support leap seconds.
On the time docs I see there is "support" for leap seconds when parsing with strptime
. But there is no comment about time.time()
.
I see that using time
I get:
>>> time.mktime(time.strptime('2016-06-30T23:59:59', "%Y-%m-%dT%H:%M:%S"))
1467327599.0
>>> time.mktime(time.strptime('2016-06-30T23:59:60', "%Y-%m-%dT%H:%M:%S"))
1467327600.0
>>> time.mktime(time.strptime('2016-07-01T00:00:00', "%Y-%m-%dT%H:%M:%S"))
1467327600.0
And datetime
just blows up:
>>> dt.datetime.strptime('2016-06-30T23:59:60', "%Y-%m-%dT%H:%M:%S")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: second must be in 0..59
Then what will I get at that exact time (in the middle of the leap second)?
I have read about rubber times, clocks slowing down, repeating seconds, and all kind of crazy ideas, but what should I expect on python?
Note: In case you wonder if I don't have anything better to do that care about it, a leap second is approaching!!!!