What returns python on the second jump

What returns the python time and datetime in the second jump?

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, is there any difference between py2.7 and py3?


Why is this confusing (at least for me):

From datetime docs, I see:

Unlike the time module, the datetime module does not support jump seconds.

In time docs, I see that there is β€œsupport” for seconds of jump when parsing with strptime . But there are no comments 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 explodes:

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

Then what will I get at this exact time (in the middle of a second of a jump)?

I read about rubber times, clock slowdowns, repeating seconds and all crazy ideas, but what should I expect in python?

Note. If you are wondering if I have anything better to do this, the second jump is coming !!!!

+5
source share
1 answer

Jump times are sometimes assigned manually. Currently, computer clocks do not have the ability to jump seconds; there is no standard to tell them in advance to insert it. Instead, the computer clock periodically resynchronizes its time using the NTP protocol and automatically adjusts after the jump second is inserted.

Then a computer clock usually reports the time in seconds since the era. It will be up to the datetime module to configure it to be taken into account when converting this second count to include seconds of jump. This is currently not happening. time.time() will simply report a time count based on seconds starting from an era.

So, nothing will change when the second jump is officially operational, except that your computer clock will be 1 second less.

The problems associated with datetime only cover the timestamp of the transition time, which it cannot be. In any case, this is not requested.

+3
source

All Articles