New Feature: Ability to add new timezones.

Asked by T J on 2015-08-31

I've needed to create custom timezones and make them available to pytz. Presently, I do this via monkeypatching, but it would be nice if this were officially supported. I'd like to be able to provide the location of a tzfile, or give it a name and DstTzInfo instance.

Question information

Language:
English Edit question
Status:
Solved
For:
pytz Edit question
Assignee:
No assignee Edit question
Solved by:
T J
Solved:
2015-09-01
Last query:
2015-09-01
Last reply:
2015-09-01
Stuart Bishop (stub) said : #1

This should work:

with open(filename, 'rb') as f:
    tzinfo = tzfile.build_tzinfo(zonename, f)

If this is good enough, it could be officially supported.

T J (tjhnson) said : #2

Yes, that should work just fine. I'll leave it to you to decide whether this should also populate pytz.all_timezones and pytz.all_timezones_set. The idea being that the custom timezones would be accessible via pytz.timezone().