[python-win32] time/datetime module wierdness on some windows7/XP PCs

raf at raf.org raf at raf.org
Wed Jul 25 08:00:33 CEST 2012


hi,

i've just noticed the following wierdness with the time and datetime modules
(python-2.6.2 and python-2.7.3) on three windows7 hosts and one windowsxp
host (but not another xp host) and i'm wondering if anyone else has
encountered this and knows how to fix it.

the first problem is that time.timezone contains 0 instead of
the usual -36000 (for Australia/Sydney).

the second problem is that time.localtime(...).is_dst is wrong.
time.tzname is also wrong but i care less about that.

the demonstration code and output is below. i can fake the
time.timezone being absent but i can't see any good way to
deal with localtime not knowing when it's daylight savings.
it appears to think it's DST when it isn't and vice versa.

this all worked before the upgrades to the new windows7 hosts.
the xp host that also exhibits the problem has recently had
its PSU, MB, CPU and RAM replaced but the HDD remains the same.
the xp host that doesn't exhibit the problem has all old hardware.
so the common factor seems to be new hardware rather than
specifically windows7.

the third problem is that datetime.datetime.now() (and time.strftime() and
time.localtime() and presumably time.time()) don't always return the
current time. sometimes they do. sometimes the "current time" jumps back
usually 9 hours for a while and then returns to normal. note that the
current time that windows displays to the user is always correct. it's just
python's idea of the current time that is wrong.

all hosts have the correct timezone (i.e. Australia/Sydney or rather
"(GMT +10:00) Canberra, Melbourne, Sydney" with automatic DST adjustment)
and automatic time synchronisation.

all hosts have the hardware clock in the local timezone and windows
doesn't have the RealTimeIsUniversal=1 registry entry so it knows
that the hardware clock is in the local timezone. so there's no
confusion there.

any help would be appreciated.

cheers,
raf

#!/usr/bin/env python
import time
print('time.timezone = %r (should be -36000)' % time.timezone)
print('time.tzname = %r (should be (\'EST\', \'EST\' or similar))' % (time.tzname,))
print('dst in june = %r (should be 0 (for Australia/Sydney))' % time.localtime(time.mktime((2012, 6, 1, 0, 0, 0, 0, 0, -1))).tm_isdst)
print('dst in december = %r (should be 1 (for Australia/Sydney))' % time.localtime(time.mktime((2012, 12, 1, 0, 0, 0, 0, 0, -1))).tm_isdst)

# Max OS X 10.6.8 (correct)
# time.timezone = -36000 (should be -36000)
# time.tzname = ('EST', 'EST') (should be ('EST', 'EST') or similar)
# dst in june = 0 (should be 0 (for Australia/Sydney))
# dst in december = 1 (should be 1 (for Australia/Sydney))

# debian-6.0 (correct)
# time.timezone = -36000 (should be -36000)
# time.tzname = ('EST', 'EST') (should be ('EST', 'EST') or similar)
# dst in june = 0 (should be 0 (for Australia/Sydney))
# dst in december = 1 (should be 1 (for Australia/Sydney))

# Windows XP Professional Service Pack 3 (correct)
# time.timezone = -36000 (should be -36000)
# time.tzname = ('AUS Eastern Standard Time', 'AUS Eastern Daylight Time') (should be ('EST', 'EST') or similar)
# dst in june = 0 (should be 0 (for Australia/Sydney))
# dst in december = 1 (should be 1 (for Australia/Sydney))

# Windows 7 and Windows XP Professional Service Pack 3 (incorrect)
# time.timezone = 0 (should be -36000)
# time.tzname = ('Aus', 'tra') (should be ('EST', 'EST') or similar)
# dst in june = 1 (should be 0 (for Australia/Sydney))
# dst in december = 0 (should be 1 (for Australia/Sydney))



More information about the python-win32 mailing list