Bugs item #1587646, was opened at 2006-10-30 19:35
Message generated for change (Comment added) made by jaraco
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=551954&aid=1587646&group_id=78018
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: win32
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Cameron LEE (noremac_eel)
Assigned to: Nobody/Anonymous (nobody)
Summary: win32timezone: southern hemisphere daylight savings problem
Initial Comment:
I found a bug in the win32timezone: It doesn’t handle
daylight savings for us poor southern hemispherians.
The logic works great for the northerners as your
summer is in the middle of the year. Ours however
straddles 2 years.
The following fixes that. My logic was that if the dst
start month was higher than august, then you aren’t in
the north.
def dst( self, dt ):
"Calculates the daylight savings offset
according to the datetime.tzinfo spec"
if dt is None: return
assert dt.tzinfo is self
result = self.standardBiasOffset
try:
dstStart = self.GetDSTStartTime( dt.year )
dstEnd = self.GetDSTEndTime( dt.year )
if dstStart.month > 8:
if not (dstEnd < dt.replace(
tzinfo=None ) <= dstStart) and not self.fixedStandardTime:
result = self.daylightBiasOffset
else:
if dstStart <= dt.replace( tzinfo=None
) < dstEnd and not self.fixedStandardTime:
result = self.daylightBiasOffset
except ValueError:
# there was an error parsing the time zone,
which is normal when a
# start and end time are not specified.
pass
return result
----------------------------------------------------------------------
Comment By: Jason R. Coombs (jaraco)
Date: 2006-10-31 06:50
Message:
Logged In: YES
user_id=599869
Here is another version of the patch that addresses the
encoding issue.
--- win32timezone.py 2006-01-03 04:12:38.000000000 -0500
+++ win32timezone.py 2006-10-31 08:42:45.803675100 -0500
@@ -12,7 +12,7 @@
This module may be tested using the doctest module.
Written by Jason R. Coombs (ja...@ja...).
- Copyright © 2003.
+ Copyright © 2003-2006.
All Rights Reserved.
To use this time zone module with the datetime module,
simply pass
@@ -67,13 +67,31 @@
>>> tz = win32timezone.TimeZoneInfo( 'China Standard Time' )
>>> tz == pickle.loads( pickle.dumps( tz ) )
True
+
+>>> aest = win32timezone.TimeZoneInfo( 'AUS Eastern
Standard Time' )
+>>> est = win32timezone.TimeZoneInfo( 'E. Australia
Standard Time' )
+>>> dt = datetime.datetime( 2006, 11, 11, 1, 0, 0, tzinfo =
aest )
+>>> estdt = dt.astimezone( est )
+>>> estdt.strftime( '%Y-%m-%d %H:%M:%S' )
+'2006-11-11 00:00:00'
+
+>>> dt = datetime.datetime( 2007, 1, 12, 1, 0, 0, tzinfo =
aest )
+>>> estdt = dt.astimezone( est )
+>>> estdt.strftime( '%Y-%m-%d %H:%M:%S' )
+'2007-01-12 00:00:00'
+
+>>> dt = datetime.datetime( 2007, 6, 13, 1, 0, 0, tzinfo =
aest )
+>>> estdt = dt.astimezone( est )
+>>> estdt.strftime( '%Y-%m-%d %H:%M:%S' )
+'2007-06-13 01:00:00'
+
"""
from __future__ import generators
__author__ = 'Jason R. Coombs <ja...@ja...>'
__version__ = '$Revision: 1.5 $'[11:-2]
-__vssauthor__ = '$Author: mhammond $'[9:-2]
-__date__ = '$Modtime: 04-04-14 10:52 $'[10:-2]
+__sccauthor__ = '$Author: mhammond $'[9:-2]
+__date__ = '$Date: 04-04-14 10:52 $'[10:-2]
import os, _winreg, struct, datetime
@@ -168,8 +186,15 @@
try:
dstStart = self.GetDSTStartTime( dt.year )
dstEnd = self.GetDSTEndTime( dt.year )
+
+ if dstStart > dstEnd:
+ inDaylightSavings = dstStart <= dt.replace( tzinfo=None
) < dstEnd
+ else:
+ # in the southern hemisphere, daylight savings time
+ # typically ends before it begins in a given year.
+ inDaylightSavings = not ( dstEnd < dt.replace(
tzinfo=None ) <= dstStart )
- if dstStart <= dt.replace( tzinfo=None ) < dstEnd and
not self.fixedStandardTime:
+ if inDaylightSavings and not self.fixedStandardTime:
result = self.daylightBiasOffset
except ValueError:
# there was an error parsing the time zone, which is
normal when a
----------------------------------------------------------------------
Comment By: Jason R. Coombs (jaraco)
Date: 2006-10-31 06:34
Message:
Logged In: YES
user_id=599869
I'm sorry. I did address this when I got the initial e-mail
from Cameron. I had started to code a fix and then ran into
some difficulty with date ranges, so put it on my task list,
but hadn't gotten to it. Thanks for bumping me on this.
I did the same thing as Mark at first, but then realized
that only addresses the issue for the latter part of the
year. If the time in question is in January, for example,
the range of interest is ( GetDSTStartTime( dt.year-1),
GetDSTEndTime( dt.year ) ).
Therefore, I've coded the patch somewhat differently. I
tried to do something more elegant, but it seems the best
approach for the southern hemisphere is to test for
exclusion from daylight savings time, as inclusion from
daylight savings time includes two distinct periods for a
given year.
Here is another patch with some additional test cases that
demonstrates correct functional behavior in all three parts
of the year for the southern hemisphere timezones.
Comments greatly appreciated.
Patch follows (as I don't appear to have access to submit
files).
--- win32timezone.py 2006-01-03 04:12:38.000000000 -0500
+++ win32timezone.py 2006-10-31 08:26:26.803675100 -0500
@@ -12,7 +12,7 @@
This module may be tested using the doctest module.
Written by Jason R. Coombs (ja...@ja...).
- Copyright © 2003.
+ Copyright © 2003-2006.
All Rights Reserved.
To use this time zone module with the datetime module,
simply pass
@@ -67,13 +67,31 @@
>>> tz = win32timezone.TimeZoneInfo( 'China Standard Time' )
>>> tz == pickle.loads( pickle.dumps( tz ) )
True
+
+>>> aest = win32timezone.TimeZoneInfo( 'AUS Eastern
Standard Time' )
+>>> est = win32timezone.TimeZoneInfo( 'E. Australia
Standard Time' )
+>>> dt = datetime.datetime( 2006, 11, 11, 1, 0, 0, tzinfo =
aest )
+>>> estdt = dt.astimezone( est )
+>>> estdt.strftime( '%Y-%m-%d %H:%M:%S' )
+'2006-11-11 00:00:00'
+
+>>> dt = datetime.datetime( 2007, 1, 12, 1, 0, 0, tzinfo =
aest )
+>>> estdt = dt.astimezone( est )
+>>> estdt.strftime( '%Y-%m-%d %H:%M:%S' )
+'2007-01-12 00:00:00'
+
+>>> dt = datetime.datetime( 2007, 6, 13, 1, 0, 0, tzinfo =
aest )
+>>> estdt = dt.astimezone( est )
+>>> estdt.strftime( '%Y-%m-%d %H:%M:%S' )
+'2007-06-13 01:00:00'
+
"""
from __future__ import generators
__author__ = 'Jason R. Coombs <ja...@ja...>'
__version__ = '$Revision: 1.5 $'[11:-2]
-__vssauthor__ = '$Author: mhammond $'[9:-2]
-__date__ = '$Modtime: 04-04-14 10:52 $'[10:-2]
+__sccauthor__ = '$Author: mhammond $'[9:-2]
+__date__ = '$Date: 04-04-14 10:52 $'[10:-2]
import os, _winreg, struct, datetime
@@ -168,8 +186,15 @@
try:
dstStart = self.GetDSTStartTime( dt.year )
dstEnd = self.GetDSTEndTime( dt.year )
+
+ if dstStart > dstEnd:
+ inDaylightSavings = dstStart <= dt.replace( tzinfo=None
) < dstEnd
+ else:
+ # in the southern hemisphere, daylight savings time
+ # typically ends before it begins in a given year.
+ inDaylightSavings = not ( dstEnd < dt.replace(
tzinfo=None ) <= dstStart )
- if dstStart <= dt.replace( tzinfo=None ) < dstEnd and
not self.fixedStandardTime:
+ if inDaylightSavings and not self.fixedStandardTime:
result = self.daylightBiasOffset
except ValueError:
# there was an error parsing the time zone, which is
normal when a
----------------------------------------------------------------------
Comment By: Mark Hammond (mhammond)
Date: 2006-10-30 22:22
Message:
Logged In: YES
user_id=14198
It appears your editor changed the whitespace in the file,
and modified the utf8 'copyright' character. I've attached
the changes as a patch and asked Jason to have a quick look.
Thanks,
Mark
----------------------------------------------------------------------
Comment By: Cameron LEE (noremac_eel)
Date: 2006-10-30 21:50
Message:
Logged In: YES
user_id=284417
p.s. am in sunny Queensland :-)
BrisVegus.
Cameron.
----------------------------------------------------------------------
Comment By: Cameron LEE (noremac_eel)
Date: 2006-10-30 21:48
Message:
Logged In: YES
user_id=284417
hope this is what yu are after.
appended to bottom of module doctests
----------------------------------------------------------------------
Comment By: Mark Hammond (mhammond)
Date: 2006-10-30 21:05
Message:
Logged In: YES
user_id=14198
I meant to ask this before, but can you please also give me
an example of code that failed and works with the patch?
I'm in Melbourne so should be able to test easily :)
Thanks
----------------------------------------------------------------------
Comment By: Cameron LEE (noremac_eel)
Date: 2006-10-30 20:24
Message:
Logged In: YES
user_id=284417
yes, much nicer! :-)
also need to update value for dstend.
(attached)
Cheers,
Cameron.
----------------------------------------------------------------------
Comment By: Mark Hammond (mhammond)
Date: 2006-10-30 19:50
Message:
Logged In: YES
user_id=14198
Wouldn't a better fix be to check if dstStart > dstEnd
rather than assuming something special about August?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=551954&aid=1587646&group_id=78018
|