New Feature: Ability to add new timezones.

Asked by T J

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:
Last query:
Last reply:
Revision history for this message
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.

Revision history for this message
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().