Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to get DST rules and timezone shortname for both standard time and daylight savings time from pytz? #117

Closed
ggiesen opened this issue Jan 24, 2024 · 1 comment

Comments

@ggiesen
Copy link

ggiesen commented Jan 24, 2024

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:

  1. 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.

  2. 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
@stub42
Copy link
Owner

stub42 commented Jan 29, 2024

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.

@stub42 stub42 closed this as completed Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants