Lines Matching refs:tzinfo
58 objects have an optional time zone information attribute, :attr:`!tzinfo`, that
59 can be set to an instance of a subclass of the abstract :class:`tzinfo` class.
60 These :class:`tzinfo` objects capture information about the offset from UTC
63 Only one concrete :class:`tzinfo` class, the :class:`timezone` class, is
104 and :attr:`.tzinfo`.
112 and :attr:`.tzinfo`.
122 .. class:: tzinfo
133 A class that implements the :class:`tzinfo` abstract base class as a
144 tzinfo
170 1. ``d.tzinfo`` is not ``None``
171 2. ``d.tzinfo.utcoffset(d)`` does not return ``None``
177 1. ``t.tzinfo`` is not ``None``
178 2. ``t.tzinfo.utcoffset(None)`` does not return ``None``.
828 .. class:: datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fo…
830 The *year*, *month* and *day* arguments are required. *tzinfo* may be ``None``, or an
831 instance of a :class:`tzinfo` subclass. The remaining arguments must be integers
852 Return the current local datetime, with :attr:`.tzinfo` ``None``.
873 If *tz* is not ``None``, it must be an instance of a :class:`tzinfo` subclass,
881 Return the current UTC date and time, with :attr:`.tzinfo` ``None``.
902 If *tz* is not ``None``, it must be an instance of a :class:`tzinfo` subclass, and the
929 :attr:`.tzinfo` ``None``. (The resulting object is naive.)
943 datetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(seconds=timestamp)
968 microsecond of the result are all 0, and :attr:`.tzinfo` is ``None``.
971 .. classmethod:: datetime.combine(date, time, tzinfo=self.tzinfo)
975 are equal to the given :class:`.time` object's. If the *tzinfo*
976 argument is provided, its value is used to set the :attr:`.tzinfo` attribute
977 of the result, otherwise the :attr:`~.time.tzinfo` attribute of the *time* argument
981 ``d == datetime.combine(d.date(), d.time(), d.tzinfo)``. If date is a
982 :class:`.datetime` object, its time components and :attr:`.tzinfo` attributes
986 Added the *tzinfo* argument.
1019 datetime.datetime(2011, 11, 4, 0, 5, 23, 283000, tzinfo=datetime.timezone.utc)
1022 tzinfo=datetime.timezone(datetime.timedelta(seconds=14400)))
1056 tzinfo=None)``.
1062 59, 999999, tzinfo=None)``.
1108 .. attribute:: datetime.tzinfo
1110 The object passed as the *tzinfo* argument to the :class:`.datetime` constructor,
1142 result has the same :attr:`~.datetime.tzinfo` attribute as the input datetime, and
1150 addition, the result has the same :attr:`~.datetime.tzinfo` attribute as the input
1158 If both are naive, or both are aware and have the same :attr:`~.datetime.tzinfo` attribute,
1159 the :attr:`~.datetime.tzinfo` attributes are ignored, and the result is a :class:`timedelta`
1163 If both are aware and have different :attr:`~.datetime.tzinfo` attributes, ``a-b`` acts
1165 result is ``(a.replace(tzinfo=None) - a.utcoffset()) - (b.replace(tzinfo=None)
1176 If both comparands are aware, and have the same :attr:`~.datetime.tzinfo` attribute, the
1177 common :attr:`~.datetime.tzinfo` attribute is ignored and the base datetimes are
1178 compared. If both comparands are aware and have different :attr:`~.datetime.tzinfo`
1208 :attr:`.tzinfo` is ``None``. See also method :meth:`timetz`.
1217 tzinfo attributes. See also method :meth:`time`.
1225 tzinfo=self.tzinfo, *, fold=0)
1229 ``tzinfo=None`` can be specified to create a naive datetime from an aware
1238 Return a :class:`.datetime` object with new :attr:`.tzinfo` attribute *tz*,
1242 If provided, *tz* must be an instance of a :class:`tzinfo` subclass, and its
1247 timezone is assumed for the target timezone. The ``.tzinfo`` attribute of the converted
1251 If ``self.tzinfo`` is *tz*, ``self.astimezone(tz)`` is equal to *self*: no
1258 adjustment of date and time data, use ``dt.replace(tzinfo=tz)``. If you
1260 conversion of date and time data, use ``dt.replace(tzinfo=None)``.
1262 Note that the default :meth:`tzinfo.fromutc` method can be overridden in a
1263 :class:`tzinfo` subclass to affect the result returned by :meth:`astimezone`.
1267 if self.tzinfo is tz:
1270 utc = (self - self.utcoffset()).replace(tzinfo=tz)
1284 If :attr:`.tzinfo` is ``None``, returns ``None``, else returns
1285 ``self.tzinfo.utcoffset(self)``, and raises an exception if the latter doesn't
1294 If :attr:`.tzinfo` is ``None``, returns ``None``, else returns
1295 ``self.tzinfo.dst(self)``, and raises an exception if the latter doesn't return
1304 If :attr:`.tzinfo` is ``None``, returns ``None``, else returns
1305 ``self.tzinfo.tzname(self)``, raises an exception if the latter doesn't return
1322 :meth:`dst` method: :attr:`.tzinfo` is ``None`` or :meth:`dst` returns
1347 ``datetime.replace(tzinfo=timezone.utc)`` to make it aware, at which point
1371 (dt - datetime(1970, 1, 1, tzinfo=timezone.utc)).total_seconds()
1385 ``tzinfo=timezone.utc``::
1387 timestamp = dt.replace(tzinfo=timezone.utc).timestamp()
1431 >>> datetime(2019, 5, 18, 15, 17, tzinfo=timezone.utc).isoformat()
1437 >>> from datetime import tzinfo, timedelta, datetime
1438 >>> class TZ(tzinfo):
1443 >>> datetime(2002, 12, 25, tzinfo=TZ()).isoformat(' ')
1445 >>> datetime(2009, 11, 27, microsecond=100, tzinfo=TZ()).isoformat()
1539 datetime.datetime(2007, 12, 6, 15, 29, 43, 79060, tzinfo=datetime.timezone.utc)
1559 -1 # dst - method tzinfo.dst() returned None
1576 The example below defines a :class:`tzinfo` subclass capturing time zone
1580 from datetime import timedelta, datetime, tzinfo, timezone
1582 class KabulTz(tzinfo):
1584 UTC_MOVE_DATE = datetime(1944, 12, 31, 20, tzinfo=timezone.utc)
1599 # Follow same validations as in datetime.tzinfo
1602 if dt.tzinfo is not self:
1603 raise ValueError("dt.tzinfo is not self")
1607 # but with a tzinfo set to self.
1609 if dt.replace(tzinfo=timezone.utc) >= self.UTC_MOVE_DATE:
1628 >>> dt1 = datetime(1900, 11, 21, 16, 30, tzinfo=tz1)
1633 >>> dt2 = datetime(2006, 6, 14, 13, 0, tzinfo=tz1)
1640 datetime.datetime(2006, 6, 14, 8, 30, tzinfo=datetime.timezone.utc)
1642 datetime.datetime(2006, 6, 14, 13, 0, tzinfo=KabulTz())
1652 day, and subject to adjustment via a :class:`tzinfo` object.
1654 .. class:: time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0)
1656 All arguments are optional. *tzinfo* may be ``None``, or an instance of a
1657 :class:`tzinfo` subclass. The remaining arguments must be integers in the
1667 default to ``0`` except *tzinfo*, which defaults to :const:`None`.
1711 .. attribute:: time.tzinfo
1713 The object passed as the tzinfo argument to the :class:`.time` constructor, or
1734 the same :attr:`~time.tzinfo` attribute, the common :attr:`~time.tzinfo` attribute is
1736 have different :attr:`~time.tzinfo` attributes, the comparands are first adjusted by
1781 datetime.time(4, 23, 1, tzinfo=datetime.timezone(datetime.timedelta(seconds=14400)))
1789 microsecond=self.microsecond, tzinfo=self.tzinfo, *, fold=0)
1793 ``tzinfo=None`` can be specified to create a naive :class:`.time` from an
1867 If :attr:`.tzinfo` is ``None``, returns ``None``, else returns
1868 ``self.tzinfo.utcoffset(None)``, and raises an exception if the latter doesn't
1877 If :attr:`.tzinfo` is ``None``, returns ``None``, else returns
1878 ``self.tzinfo.dst(None)``, and raises an exception if the latter doesn't return
1886 If :attr:`.tzinfo` is ``None``, returns ``None``, else returns
1887 ``self.tzinfo.tzname(None)``, or raises an exception if the latter doesn't
1895 >>> from datetime import time, tzinfo, timedelta
1896 >>> class TZ1(tzinfo):
1906 >>> t = time(12, 10, 30, tzinfo=TZ1())
1908 datetime.time(12, 10, 30, tzinfo=TZ1())
1921 .. _datetime-tzinfo:
1923 :class:`tzinfo` Objects
1926 .. class:: tzinfo()
1929 instantiated directly. Define a subclass of :class:`tzinfo` to capture
1932 An instance of (a concrete subclass of) :class:`tzinfo` can be passed to the
1934 view their attributes as being in local time, and the :class:`tzinfo` object
1939 supply implementations of the standard :class:`tzinfo` methods needed by the
1941 :class:`timezone`, a simple concrete subclass of :class:`tzinfo` which can
1945 Special requirement for pickling: A :class:`tzinfo` subclass must have an
1950 A concrete subclass of :class:`tzinfo` may need to implement the following
1955 .. method:: tzinfo.utcoffset(dt)
1961 :class:`tzinfo` object represents both time zone and DST adjustments,
1981 .. method:: tzinfo.dst(dt)
1992 separately. For example, :meth:`datetime.timetuple` calls its :attr:`~.datetime.tzinfo`
1994 should be set, and :meth:`tzinfo.fromutc` calls :meth:`dst` to account for
1997 An instance *tz* of a :class:`tzinfo` subclass that models both standard and
2002 must return the same result for every :class:`.datetime` *dt* with ``dt.tzinfo ==
2003 tz`` For sane :class:`tzinfo` subclasses, this expression yields the time
2007 responsibility to ensure it. If a :class:`tzinfo` subclass cannot guarantee
2009 :meth:`tzinfo.fromutc` to work correctly with :meth:`astimezone` regardless.
2024 if dston <= dt.replace(tzinfo=None) < dstoff:
2035 .. method:: tzinfo.tzname(dt)
2042 a method rather than a fixed string primarily because some :class:`tzinfo`
2044 of *dt* passed, especially if the :class:`tzinfo` class is accounting for
2053 argument. A :class:`tzinfo` subclass's methods should therefore be prepared to
2058 say that time objects don't participate in the :class:`tzinfo` protocols. It
2063 method, ``dt.tzinfo`` is the same object as *self*. :class:`tzinfo` methods can
2064 rely on this, unless user code calls :class:`tzinfo` methods directly. The
2065 intent is that the :class:`tzinfo` methods interpret *dt* as being in local
2068 There is one more :class:`tzinfo` method that a subclass may wish to override:
2071 .. method:: tzinfo.fromutc(dt)
2074 implementation. When called from that, ``dt.tzinfo`` is *self*, and *dt*'s
2079 Most :class:`tzinfo` subclasses should be able to inherit the default
2094 # raise ValueError error if dt.tzinfo is not self
2110 :class:`tzinfo` classes:
2114 Note that there are unavoidable subtleties twice per year in a :class:`tzinfo`
2135 >>> u0 = datetime(2016, 3, 13, 5, tzinfo=timezone.utc)
2158 >>> u0 = datetime(2016, 11, 6, 4, tzinfo=timezone.utc)
2174 :class:`tzinfo` subclasses; there are no ambiguities when using :class:`timezone`,
2175 or any other fixed-offset :class:`tzinfo` subclass (such as a class representing
2201 The :class:`timezone` class is a subclass of :class:`tzinfo`, each
2260 :class:`.datetime` instance, with ``tzinfo`` set to ``self``.
2557 aware :class:`.datetime` object will be produced. The ``tzinfo`` of the