tz¶
-
class
dateutil.tz.tzutc[source]¶ This is a tzinfo object that represents the UTC time zone.
-
fromutc(dt)[source]¶ Fast track version of fromutc() returns the original
dtobject for any validdatetime.datetimeobject.
-
is_ambiguous(dt)[source]¶ Whether or not the “wall time” of a given datetime is ambiguous in this zone.
Parameters: dt – A datetime.datetime, naive or time zone aware.Returns: Returns Trueif ambiguous,Falseotherwise.New in version 2.6.0.
-
tzname(**kwargs)¶
-
-
class
dateutil.tz.tzoffset(name, offset)[source]¶ A simple class for representing a fixed offset from UTC.
Parameters: - name – The timezone name, to be returned when
tzname()is called. - offset – The time zone offset in seconds, or (since version 2.6.0, represented
as a
datetime.timedeltaobject.
-
is_ambiguous(dt)[source]¶ Whether or not the “wall time” of a given datetime is ambiguous in this zone.
Parameters: dt – A datetime.datetime, naive or time zone aware.Returns: Returns Trueif ambiguous,Falseotherwise.New in version 2.6.0.
-
tzname(**kwargs)¶
- name – The timezone name, to be returned when
-
class
dateutil.tz.tzlocal[source]¶ A
tzinfosubclass built around thetimetimezone functions.-
is_ambiguous(dt)[source]¶ Whether or not the “wall time” of a given datetime is ambiguous in this zone.
Parameters: dt – A datetime.datetime, naive or time zone aware.Returns: Returns Trueif ambiguous,Falseotherwise.New in version 2.6.0.
-
tzname(**kwargs)¶
-
-
class
dateutil.tz.tzfile(fileobj, filename=None)[source]¶ This is a
tzinfosubclass thant allows one to use thetzfile(5)format timezone files to extract current and historical zone information.Parameters: - fileobj – This can be an opened file stream or a file name that the time zone information can be read from.
- filename – This is an optional parameter specifying the source of the time zone
information in the event that
fileobjis a file object. If omitted andfileobjis a file stream, this parameter will be set either tofileobj’snameattribute or torepr(fileobj).
See Sources for Time Zone and Daylight Saving Time Data for more information. Time zone files can be compiled from the IANA Time Zone database files with the zic time zone compiler
-
fromutc(dt)[source]¶ The
tzfileimplementation ofdatetime.tzinfo.fromutc().Parameters: dt – A
datetime.datetimeobject.Raises: - TypeError – Raised if
dtis not adatetime.datetimeobject. - ValueError – Raised if this is called with a
dtwhich does not have thistzinfoattached.
Returns: Returns a
datetime.datetimeobject representing the wall time inself’s time zone.- TypeError – Raised if
-
is_ambiguous(dt, idx=None)[source]¶ Whether or not the “wall time” of a given datetime is ambiguous in this zone.
Parameters: dt – A datetime.datetime, naive or time zone aware.Returns: Returns Trueif ambiguous,Falseotherwise.New in version 2.6.0.
-
tzname(**kwargs)¶
-
class
dateutil.tz.tzrange(stdabbr, stdoffset=None, dstabbr=None, dstoffset=None, start=None, end=None)[source]¶ The
tzrangeobject is a time zone specified by a set of offsets and abbreviations, equivalent to the way theTZvariable can be specified in POSIX-like systems, but using Python delta objects to specify DST start, end and offsets.Parameters: - stdabbr – The abbreviation for standard time (e.g.
'EST'). - stdoffset –
An integer or
datetime.timedeltaobject or equivalent specifying the base offset from UTC.If unspecified, +00:00 is used.
- dstabbr –
The abbreviation for DST / “Summer” time (e.g.
'EDT').If specified, with no other DST information, DST is assumed to occur and the default behavior or
dstoffset,startandendis used. If unspecified and no other DST information is specified, it is assumed that this zone has no DST.If this is unspecified and other DST information is is specified, DST occurs in the zone but the time zone abbreviation is left unchanged.
- dstoffset – A an integer or
datetime.timedeltaobject or equivalent specifying the UTC offset during DST. If unspecified and any other DST information is specified, it is assumed to be the STD offset +1 hour. - start –
A
relativedelta.relativedeltaobject or equivalent specifying the time and time of year that daylight savings time starts. To specify, for example, that DST starts at 2AM on the 2nd Sunday in March, pass:relativedelta(hours=2, month=3, day=1, weekday=SU(+2))If unspecified and any other DST information is specified, the default value is 2 AM on the first Sunday in April.
- end – A
relativedelta.relativedeltaobject or equivalent representing the time and time of year that daylight savings time ends, with the same specification method as instart. One note is that this should point to the first time in the standard zone, so if a transition occurs at 2AM in the DST zone and the clocks are set back 1 hour to 1AM, set the hours parameter to +1.
Examples:
>>> tzstr('EST5EDT') == tzrange("EST", -18000, "EDT") True >>> from dateutil.relativedelta import * >>> range1 = tzrange("EST", -18000, "EDT") >>> range2 = tzrange("EST", -18000, "EDT", -14400, ... relativedelta(hours=+2, month=4, day=1, ... weekday=SU(+1)), ... relativedelta(hours=+1, month=10, day=31, ... weekday=SU(-1))) >>> tzstr('EST5EDT') == range1 == range2 True
-
transitions(year)[source]¶ For a given year, get the DST on and off transition times, expressed always on the standard time side. For zones with no transitions, this function returns
None.Parameters: year – The year whose transitions you would like to query. Returns: Returns a tupleofdatetime.datetimeobjects,(dston, dstoff)for zones with an annual DST transition, orNonefor fixed offset zones.
- stdabbr – The abbreviation for standard time (e.g.
-
class
dateutil.tz.tzstr(s, posix_offset=False)[source]¶ tzstrobjects are time zone objects specified by a time-zone string as it would be passed to aTZvariable on POSIX-style systems (see the GNU C Library: TZ Variable for more details).There is one notable exception, which is that POSIX-style time zones use an inverted offset format, so normally
GMT+3would be parsed as an offset 3 hours behind GMT. Thetzstrtime zone object will parse this as an offset 3 hours ahead of GMT. If you would like to maintain the POSIX behavior, pass aTruevalue toposix_offset.The
tzrangeobject provides the same functionality, but is specified usingrelativedelta.relativedeltaobjects. rather than strings.Parameters: - s – A time zone string in
TZvariable format. This can be abytes(2.x:str),str(2.x:unicode) or a stream emitting unicode characters (e.g.StringIO). - posix_offset – Optional. If set to
True, interpret strings such asGMT+3orUTC+3as being 3 hours behind UTC rather than ahead, per the POSIX standard.
- s – A time zone string in
-
class
dateutil.tz.tzical(fileobj)[source]¶ This object is designed to parse an iCalendar-style
VTIMEZONEstructure as set out in RFC 2445 Section 4.6.5 into one or more tzinfo objects.Parameters: fileobj – A file or stream in iCalendar format, which should be UTF-8 encoded with CRLF endings. -
get(tzid=None)[source]¶ Retrieve a
datetime.tzinfoobject by itstzid.Parameters: tzid – If there is exactly one time zone available, omitting tzidor passingNonevalue returns it. Otherwise a valid key (which can be retrieved fromkeys()) is required.Raises: ValueError – Raised if tzidis not specified but there are either more or fewer than 1 zone defined.Returns: Returns either a datetime.tzinfoobject representing the relevant time zone orNoneif thetzidwas not found.
-
-
dateutil.tz.enfold(dt, fold=1)[source]¶ Provides a unified interface for assigning the
foldattribute to datetimes both before and after the implementation of PEP-495.Parameters: fold – The value for the foldattribute in the returned datetime. This should be either 0 or 1.Returns: Returns an object for which getattr(dt, 'fold', 0)returnsfoldfor all versions of Python. In versions prior to Python 3.6, this is a_DatetimeWithFoldobject, which is a subclass ofdatetime.datetimewith thefoldattribute added, iffoldis 1.New in version 2.6.0.
-
dateutil.tz.datetime_ambiguous(dt, tz=None)[source]¶ Given a datetime and a time zone, determine whether or not a given datetime is ambiguous (i.e if there are two times differentiated only by their DST status).
Parameters: - dt – A
datetime.datetime(whose time zone will be ignored iftzis provided.) - tz – A
datetime.tzinfowith support for thefoldattribute. IfNoneor not provided, the datetime’s own time zone will be used.
Returns: Returns a boolean value whether or not the “wall time” is ambiguous in
tz.New in version 2.6.0.
- dt – A
-
dateutil.tz.datetime_exists(dt, tz=None)[source]¶ Given a datetime and a time zone, determine whether or not a given datetime would fall in a gap.
Parameters: - dt – A
datetime.datetime(whose time zone will be ignored iftzis provided.) - tz – A
datetime.tzinfowith support for thefoldattribute. IfNoneor not provided, the datetime’s own time zone will be used.
Returns: Returns a boolean value whether or not the “wall time” exists in
tz.- dt – A