Why does pytz correctly adjust time and offset when crossing TZ and DST borders, but not TZ name?

I have reviewed a few pytz related issues pytz , but no one seems to address the specific issue I am seeing.

Following the pytz documentation , here's a loop for printing the current time in several time zones, including the time zone offset, the time zone name, and whether the datetime object is its 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 conclusion:

 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 this information is correct, including the time, offset, and time in Sydney at 1:00:00 , indicating that the datetime object believes that the DST is currently operating in Sydney.

The only problem is that Sydney time is marked EST instead of EDT . In fact, I can't get Python to ever declare Sydney in EDT , although 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())) 

Conclusion:

 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 deprecated on my system? Is this a known issue fixed in recent versions of pytz or Olson DB that I may not have? (Mine says it uses OLSON_VERSION = '2010b' .)

+2
source share
1 answer

IANA maintains the Olson database. The question of what time zone shorthand should be used for Australia was discussed on the IANA tz mailing list here (discussion lasted two months: March 2013 , April 2013 ).

Apparently, all parties have a clear opinion on what abbreviations should be, and these strong opinions have led to a deadlock.

Some say abbreviations are a relic of the past and should not be used, and ambiguity should not be fixed to discourage its use.

There are apparently no recognized authorities in Australia to define abbreviations. Some say conflicting organizations use different time zone reductions , and in order not to choose political parties, IANA chose EST for both standard and summer periods.

Olson DB currently uses EST for all time zones 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 time zone, EST is used at each crossing border.

+4
source

Source: https://habr.com/ru/post/1202276/


All Articles