Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happened on March 16th 1984?

I am trying to figure out what's special about March 16th, 1984. On a virtual machine I am using (nothing special about it), Python (as well as PyPy) crashes when trying to use mktime with what seems to be a perfectly reasonable time struct.

$ pypy
Python 2.7.3 (f66246c46ca30b26a5c73e4cc95dd6235c966b8f, Jul 30 2013, 09:27:06)
[PyPy 2.0.2 with GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>> import time
>>>> time.mktime((1984,3,16,0,0,0,0,0,0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: mktime argument out of range
>>>> time.mktime((1984,3,15,0,0,0,0,0,0))
448156800.0
>>>> time.mktime((1984,3,17,0,0,0,0,0,0))
448326000.0
>>>> time.mktime((1984,3,16,0,0,0,0,0,0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: mktime argument out of range
>>>> 

Why and what can be done to avoid this issue?

Although the problem does happen every time on this VM, I could not make it occur on any other.

like image 207
Benoît Avatar asked Sep 23 '13 02:09

Benoît


2 Answers

Aha! Mystery solved (since OP finally figured out the time zone "at fault"). I found this:

http://www.timeanddate.com/worldclock/timezone.html?n=60&syear=1980

1980    No time changes  
1981    No time changes  
1982    No time changes  
1983    No time changes  
1984    Time zone change on Friday, March 16, 1984 at 1:00:00 AM     
1985    Time zone change on Tuesday, December 31, 1985 at 11:00:00 PM    
1986    No time changes  
1987    No time changes  
1988    No time changes  
1989    No time changes  

So, I guess the answer to "What happened on March 16th 1984" is that Casablanca changed its time at 1:00 AM that day. :)

And technically, it jumped immediately from midnight to 1:00 AM, so probably all times starting at 00:00 and just before 01:00 will produce the same error. That is, my guess is that time.mktime((1984,3,16,1,0,0,0,0,0)) and greater will work, but for example, time.mktime((1984,3,16,0,59,0,0,0,0)) will not.

like image 73
John Y Avatar answered Sep 22 '22 13:09

John Y


Your machine thinks that there was a daylight savings transition between midnight on 15th March 1984 and midnight on 17th March 1984, given that the difference between 448326000.0 and 448156800.0 is 47 hours, not 48.

But so far as I can tell, no such transition occurred on that day in France. And I'm not sure how you fix your OS's interpretation of historic daylight savings transitions.

like image 26
Damien_The_Unbeliever Avatar answered Sep 18 '22 13:09

Damien_The_Unbeliever