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'
.)