This is a ``tzinfo`` subclass that allows one to use the ``tzfile(5)`` format timezone files to extract current and historical zone information. :param fileobj: This can be an opened file stream or a file name that the time zone information can be read from. :param filename: This is an optional parameter specifying the source of the time zone information in the event that ``fileobj`` is a file object. If omitted and ``fileobj`` is a file stream, this parameter will be set either to ``fileobj``'s ``name`` attribute or to ``repr(fileobj)``. See `Sources for Time Zone and Daylight Saving Time Data <https://data.iana.org/time-zones/tz-link.html>`_ for more information. Time zone files can be compiled from the `IANA Time Zone database files <https://www.iana.org/time-zones>`_ with the `zic time zone compiler <https://www.freebsd.org/cgi/man.cgi?query=zic&sektion=8>`_ .. note:: Only construct a ``tzfile`` directly if you have a specific timezone file on disk that you want to read into a Python ``tzinfo`` object. If you want to get a ``tzfile`` representing a specific IANA zone, (e.g. ``'America/New_York'``), you should call :func:`dateutil.tz.gettz` with the zone identifier. **Examples:** Using the US Eastern time zone as an example, we can see that a ``tzfile`` provides time zone information for the standard Daylight Saving offsets: .. testsetup:: tzfile from dateutil.tz import gettz from datetime import datetime .. doctest:: tzfile >>> NYC = gettz('America/New_York') >>> NYC tzfile('/usr/share/zoneinfo/America/New_York') >>> print(datetime(2016, 1, 3, tzinfo=NYC)) # EST 2016-01-03 00:00:00-05:00 >>> print(datetime(2016, 7, 7, tzinfo=NYC)) # EDT 2016-07-07 00:00:00-04:00 The ``tzfile`` structure contains a fully history of the time zone, so historical dates will also have the right offsets. For example, before the adoption of the UTC standards, New York used local solar mean time: .. doctest:: tzfile >>> print(datetime(1901, 4, 12, tzinfo=NYC)) # LMT 1901-04-12 00:00:00-04:56 And during World War II, New York was on "Eastern War Time", which was a state of permanent daylight saving time: .. doctest:: tzfile >>> print(datetime(1944, 2, 7, tzinfo=NYC)) # EWT 1944-02-07 00:00:00-04:00
Method | __eq__ |
Undocumented |
Method | __init__ |
Undocumented |
Method | __ne__ |
Undocumented |
Method | __reduce__ |
Undocumented |
Method | __reduce |
Undocumented |
Method | __repr__ |
Undocumented |
Method | dst |
Undocumented |
Method | fromutc |
The ``tzfile`` implementation of :py:func:`datetime.tzinfo.fromutc`. |
Method | is |
Whether or not the "wall time" of a given datetime is ambiguous in this zone. |
Method | tzname |
Undocumented |
Method | utcoffset |
Undocumented |
Class Variable | __hash__ |
Undocumented |
Method | _find |
Undocumented |
Method | _find |
Undocumented |
Method | _get |
Undocumented |
Method | _read |
Undocumented |
Method | _resolve |
Undocumented |
Method | _set |
Set the time zone data of this object from a _tzfile object |
Instance Variable | _filename |
Undocumented |
Inherited from _tzinfo
:
Method | _fold |
Undocumented |
Method | _fold |
Determine the fold status of a "wall" datetime, given a representation of the same datetime as a (naive) UTC datetime. This is calculated based on the assumption that ``dt.utcoffset() - dt.dst()`` is constant for all datetimes, and that this offset is the actual number of hours separating ``dt_utc`` and ``dt_wall``. |
Method | _fromutc |
Given a timezone-aware datetime in a given timezone, calculates a timezone-aware datetime in a new timezone. |
dateutil.tz._common._tzinfo.fromutc
The ``tzfile`` implementation of :py:func:`datetime.tzinfo.fromutc`. :param dt: A :py:class:`datetime.datetime` object. :raises TypeError: Raised if ``dt`` is not a :py:class:`datetime.datetime` object. :raises ValueError: Raised if this is called with a ``dt`` which does not have this ``tzinfo`` attached. :return: Returns a :py:class:`datetime.datetime` object representing the wall time in ``self``'s time zone.
dateutil.tz._common._tzinfo.is_ambiguous
Whether or not the "wall time" of a given datetime is ambiguous in this zone. :param dt: A :py:class:`datetime.datetime`, naive or time zone aware. :return: Returns ``True`` if ambiguous, ``False`` otherwise. .. versionadded:: 2.6.0