This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: mktime adding an hour in April (naive struct)?
Type: behavior Stage:
Components: Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: barnburnr, belopolsky
Priority: normal Keywords:

Created on 2010-10-14 14:08 by barnburnr, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
mktimeissue.py barnburnr, 2010-10-14 14:08 Test script
Messages (3)
msg118662 - (view) Author: Kevin Barnhart (barnburnr) Date: 2010-10-14 14:08
Just starting to dabble in the world of time and datetime objects.  I was converting an array of datetime objects to an array of floats via mktime to do some data analysis.  I have ran into an issue where mktime seems to be adding an hour on April 6, 2003.  Attached is an example script which I used to create the below output:

Python version:  (2, 6, 5, 'final', 0)
Epoch:  time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)
First datetime:  2003-04-06 02:58:17
Second datetime:  2003-04-06 03:13:17
Is first datetime prior to second?:  True
First datetime, time struct: time.struct_time(tm_year=2003, tm_mon=4, tm_mday=6, tm_hour=2, tm_min=58, tm_sec=17, tm_wday=6, tm_yday=96, tm_isdst=-1)
Second datetime, time struct: time.struct_time(tm_year=2003, tm_mon=4, tm_mday=6, tm_hour=3, tm_min=13, tm_sec=17, tm_wday=6, tm_yday=96, tm_isdst=-1)
Is first time struct prior to second?:  True
First timestamp generated by mktime:  1049623097.0
Second timestamp generated by mktime:  1049620397.0
Is first timestamp less than second timestamp?:  False
First recovered datetime:  2003-04-06 03:58:17
Second recovered datetime:  2003-04-06 03:13:17
Is first recovered prior to second recovered?:  False
Is first recovered datetime same as original?:  False
Is second recovered datetime same as original?:  True
msg118673 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-10-14 15:37
It looks like you have just discovered the joys of daylight saving time.  The problem with your example is that datetime(2003,4,6,2,58,17) is not a valid time in your timezone (most likely you are in the US).  In the US, prior to 2007, the clocks moved 1 hour ahead at 2AM on the first Sunday in April. An thus 1:59 AM was followed by 3:00 AM and 2:58:17 never occurred.

See the following link for detailed discussion of these issues:

http://docs.python.org/dev/py3k/library/datetime.html#tzinfo-objects
msg118690 - (view) Author: Kevin Barnhart (barnburnr) Date: 2010-10-14 16:54
Wow.  Should have caught that.  Thanks for the response.

Kevin
History
Date User Action Args
2022-04-11 14:57:07adminsetgithub: 54311
2010-10-14 16:54:05barnburnrsetmessages: + msg118690
2010-10-14 15:37:31belopolskysetstatus: open -> closed

nosy: + belopolsky
messages: + msg118673

resolution: not a bug
2010-10-14 14:08:02barnburnrcreate