views:

141

answers:

2

I'm using the following code in Python 2.5.1 to generate a UTC timestamp from a string representation of a date:

time.mktime(time.strptime("2009-06-16", "%Y-%m-%d"))

The general result is: 1245103200 (16.6.2009 0:00 UTC or 15.6.09 22:00:00, if you're in my time zone).

But now, I found that on some computers running Windows XP, this statement would generate a time shifted by 1 hour, 1 minute and 1 second: 1245099539 (15.6.2009 22:58:59 UTC or 15.6.09 20:58:59 in my time zone).

DST and time zone do not seem to be the cause of the problem, because the time shift seems to appear additionally to DST and time zone calculation.

Has anybody experienced the same behaviour or is able to describe what happens here?

A: 

What version of Python are you running? There are two bug descriptions here which sound a lot like what you are experiencing:

ire_and_curses
I don't think that it is a problem of DST, becausea) the time shift is not 1 h, but 1h + 1m + 1sb) the time shift seems to appear additionally to DST and time zone calculation (see above)
Bertolt
+1  A: 

Found the answer myself:

When executing the following on the python command line interface, I get the result:

time.strptime("2009-06-16", "%Y-%m-%d")
time.struct_time(tm_year=2009, tm_mon=6, tm_mday=16, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=1, tm_yday=167, tm_isdst=-1)

If I run the same command in an executable built with py2exe, it results in the following time structure:

time.struct_time(tm_year=2009, tm_mon=8, tm_mday=11, tm_hour=-1, tm_min=-1, tm_sec=-1, tm_wday=1, tm_yday=224, tm_isdst=-1)

The internal time structure apparently initializes differently on command line and when using py2exe. Fixed the problem by adding a midnight time to the command.

Bertolt