Reputation: 5663
I have reviewed several pytz
-related questions here, but none seems to address the exact problem I'm seeing.
Following the pytz documentation, here's a loop to print the current time in multiple time zones, including time zone offset, time zone name, and whether the datetime
object thinks it's DST.
nowDT = datetime.datetime.now()
chicagoTz = pytz.timezone('America/Chicago')
chicagoDT = chicagoTz.normalize(chicagoTz.localize(nowDT))
sys.stdout.write( "%-10s %-35s %s\n" % ('Chicago',
chicagoDT.strftime("%Y/%m/%d %H:%M:%S %Z %z"),
chicagoDT.dst()) )
tzTups = [('New York', 'America/New_York'),
('London', 'Europe/London'),
('Sydney', 'Australia/Sydney')]
for tzTup in tzTups:
tz = pytz.timezone(tzTup[1])
locDT = tz.normalize(chicagoDT.astimezone(tz))
sys.stdout.write( "%-10s %-35s %s\n" % (tzTup[0],
locDT.strftime("%Y/%m/%d %H:%M:%S %Z %z"),
locDT.dst()) )
Here's the output:
Chicago 2014/03/12 14:34:53 CDT -0500 1:00:00
New York 2014/03/12 15:34:53 EDT -0400 1:00:00
London 2014/03/12 19:34:53 GMT +0000 0:00:00
Sydney 2014/03/13 06:34:53 EST +1100 1:00:00
Checking with, say, timeanddate.com, we see that all of this information is correct, including the Sydney time, offset, and the 1:00:00
indicating that the datetime
object believes that DST is currently in effect in Sydney.
The only problem is that the Sydney time is labeled EST
instead of EDT
. In fact, I can't get Python to ever declare Sydney in EDT
even though it knows about the DST offset:
tz = pytz.timezone('Australia/Sydney')
for i in range(1,13):
locDT = tz.normalize(tz.localize(datetime.datetime(2013, i, 15)))
sys.stdout.write("%02d %s %s\n" % (i, locDT.dst(), locDT.tzname()))
Output:
01 1:00:00 EST
02 1:00:00 EST
03 1:00:00 EST
04 0:00:00 EST
05 0:00:00 EST
06 0:00:00 EST
07 0:00:00 EST
08 0:00:00 EST
09 0:00:00 EST
10 1:00:00 EST
11 1:00:00 EST
12 1:00:00 EST
Am I doing something wrong? Is /usr/share/zoneinfo
out of date on my system? Is this a known issue corrected in recent versions of pytz
or the Olson DB that I might not have? (Mine says it's using OLSON_VERSION = '2010b'
.)
Upvotes: 2
Views: 1022
Reputation: 880547
The IANA maintains the Olson database. The question of what timezone abbreviation(s) should be used for Australia was discussed in the IANA's tz mailing list here (the discussion spanned two months: March 2013, April 2013).
There seems to be strong opinion on all sides as to what the abbreviations should be and those strong opinions have resulted in gridlock.
Some say the abbreviations are a relic of the past and should not be used and the ambiguity should not be fixed to help discourage its use.
Apparently there is no recognized authority in Australia defining the abbreviations. Some say conflicting organizations use different timezone abbreviations, and so as not to pick political sides, the IANA chose EST for both standard and daylight savings times.
For now, the Olson DB uses EST for all timezones for all dates in Australia/Sydney:
In [60]: import pytz
In [61]: sydney = pytz.timezone('Australia/Sydney')
In [68]: [(date, tzabbrev) for date, (utcoffset, dstoffset, tzabbrev) in zip(sydney._utc_transition_times, sydney._transition_info)]
Out[68]:
[(datetime.datetime(1, 1, 1, 0, 0), 'EST'),
(datetime.datetime(1916, 12, 31, 14, 1), 'EST'),
(datetime.datetime(1917, 3, 24, 15, 0), 'EST'),
(datetime.datetime(1941, 12, 31, 16, 0), 'EST'),
(datetime.datetime(1942, 3, 28, 15, 0), 'EST'),
(datetime.datetime(1942, 9, 26, 16, 0), 'EST'),
(datetime.datetime(1943, 3, 27, 15, 0), 'EST'),
...]
In [69]: set([tzabbrev for utcoffset, dstoffset, tzabbrev in sydney._transition_info])
Out[69]: {'EST'}
This shows that in the Australia/Sydney timezone, EST is used across every transition boundary.
Upvotes: 4