Dear raf:
  Yes, time zones in the python time module are known to be somewhat messed
up.  Mark Hammond and I went several rounds while trying to create a test
for the "python time" capabilities in adodbapi.  When a test worked for me
in North America, it was almost guaranteed to fail for him in antipodes.
The problems seem to be deep in the standard library code.  We finally
concluded that we would just document the problems with "time" and suggest
that everyone use "datetime", which is considerably more capable. Time zone
aware datetime objects seemed to work perfectly. (Are you _sure_ that
datetime.datetime.now() was messing up in your situation?)

 Jason Coombs contributed the "win32timezone" module to pywin32 which makes
use of the extensive time zone support in the Windows registry.   Look it
up in your pywin32 documentation. You might be especially interested in
win32timezone.now().   If I understand what you are looking for, the return
value of win32api.GetTimeZoneInformation() might give you the correct
answer.

  So, in answer to your question "how to fix it", I would suggest that you
start with:
>>>import win32timezone, datetime

Please report back if that does not work.
--
Vernon Cole

On Wed, Jul 25, 2012 at 12:00 AM, <r...@raf.org> wrote:

> 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))
>
> _______________________________________________
> python-win32 mailing list
> python-win32@python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to