Any way to get DST rules and timezone shortname for both standard time and daylight savings time from pytz?
ggiesen opened this issue · 1 comments
Using pytz I can feed it an Olson timezone name and get the timezone shortname for any particular time (ie. "America/Toronto" is "EST" or "EDT" depending on the time I feed it). However I'd also like to get:
-
The complimentary short timezone name for whatever the current short timezone name is. Ie if pytz is returning EST, I'd like to be able to also return "EDT" as the daylight savings short time zone and vice versa. I can solve this by just iterating through a bunch of input times until the name changes, but this seems really hacky.
-
I'd like to be able to also retrieve the DST rules for a timezone. Ie changes to EDT (ie "Second Sunday in March at 02:00").
Are either of these possible with pytz (without the aforementioned hack for 1)?
Edit: Here's an example of the plaintext timezone rules from the Olson DB:
# Rule NAME FROM TO - IN ON AT SAVE LETTER/S
Rule Toronto 1919 only - Mar 30 23:30 1:00 D
Rule Toronto 1919 only - Oct 26 0:00 0 S
Rule Toronto 1920 only - May 2 2:00 1:00 D
Rule Toronto 1920 only - Sep 26 0:00 0 S
Rule Toronto 1921 only - May 15 2:00 1:00 D
Rule Toronto 1921 only - Sep 15 2:00 0 S
Rule Toronto 1922 1923 - May Sun>=8 2:00 1:00 D
Rule Toronto 1922 1926 - Sep Sun>=15 2:00 0 S
Rule Toronto 1924 1927 - May Sun>=1 2:00 1:00 D
Rule Toronto 1927 1937 - Sep Sun>=25 2:00 0 S
Rule Toronto 1928 1937 - Apr Sun>=25 2:00 1:00 D
Rule Toronto 1938 1940 - Apr lastSun 2:00 1:00 D
Rule Toronto 1938 1939 - Sep lastSun 2:00 0 S
Rule Toronto 1945 1946 - Sep lastSun 2:00 0 S
Rule Toronto 1946 only - Apr lastSun 2:00 1:00 D
Rule Toronto 1947 1949 - Apr lastSun 0:00 1:00 D
Rule Toronto 1947 1948 - Sep lastSun 0:00 0 S
Rule Toronto 1949 only - Nov lastSun 0:00 0 S
Rule Toronto 1950 1973 - Apr lastSun 2:00 1:00 D
Rule Toronto 1950 only - Nov lastSun 2:00 0 S
Rule Toronto 1951 1956 - Sep lastSun 2:00 0 S
# Zone NAME STDOFF RULES FORMAT [UNTIL]
Zone America/Toronto -5:17:32 - LMT 1895
-5:00 Canada E%sT 1919
-5:00 Toronto E%sT 1942 Feb 9 2:00s
-5:00 Canada E%sT 1946
-5:00 Toronto E%sT 1974
-5:00 Canada E%sT
# Rule NAME FROM TO - IN ON AT SAVE LETTER/S
Rule Canada 1918 only - Apr 14 2:00 1:00 D
Rule Canada 1918 only - Oct 27 2:00 0 S
Rule Canada 1942 only - Feb 9 2:00 1:00 W # War
Rule Canada 1945 only - Aug 14 23:00u 1:00 P # Peace
Rule Canada 1945 only - Sep 30 2:00 0 S
Rule Canada 1974 1986 - Apr lastSun 2:00 1:00 D
Rule Canada 1974 2006 - Oct lastSun 2:00 0 S
Rule Canada 1987 2006 - Apr Sun>=1 2:00 1:00 D
Rule Canada 2007 max - Mar Sun>=8 2:00 1:00 D
Rule Canada 2007 max - Nov Sun>=1 2:00 0 S
For 1), best that can be done is pick a time 6 months in the future and check that. It is just a heuristic though - what is your complimentary timezone if there are more than 2 transitions in a particular year?
The data for 2) is not in pytz and cannot be done. pytz uses the compiled IANA binary files, and you need to decode the source for those binary files.