Helper functions¶
This module contains helper functions to ease the transition from pytz to
another PEP 495-compatible library.
-
pytz_deprecation_shim.helpers.is_pytz_zone(tz)¶ Check if a time zone is a
pytztime zone.This will only import
pytzif it has already been imported, and does not rely on the existence of thelocalizeornormalizemethods (since the shim classes also have these methods, but are notpytzzones).
-
pytz_deprecation_shim.helpers.upgrade_tzinfo(tz)¶ Convert a
pytzor shim timezone into its modern equivalent.The shim classes are thin wrappers around
zoneinfoordateutil.tzimplementations of thedatetime.tzinfobase class. This function removes the shim and returns the underlying “upgraded” time zone.When passed a
pytzzone (not a shim), this returns the non-pytzequivalent. This may fail ifpytzis using a data source incompatible with the upgraded provider’s data source, or if thepytzzone was built from a file rather than an IANA key.When passed an object that is not a shim or a
pytzzone, this returns the original object.- Parameters
tz – A
datetime.tzinfoobject.- Raises
KeyError – If a
pytzzone is passed to the function with no equivalent in the PEP 495-compatible library’s version of the Olson database.- Returns
A PEP 495-compatible equivalent of any
pytzor shim class, or the original object.