o d@sdZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl Z ddl m Z ddl m Z ddlmZmZddlmZmZdd lmZdd lmZmZdd lmZz dd lmZmZWn eyodZZYnwdd lmZedZej dZ!e!"Z#e $eGdddej%Z&e&Z'e $eGdddej%Z(GdddeZ)Gddde*Z+Gddde*Z,GdddeZ-GdddeZ.e $eGddde.Z/Gddde*Z0Gd d!d!eZ1Gd"d#d#e*Z2ej3d$krd%d&gZ4gd'Z5ngZ4gZ5d(d)Z6e6Z7[6d9d*d+Z8d9d,d-Z9d.d/Z:d0d1Z;ejm?Z@WdSeyHGd7d8d8e*Z@YdSw):a This module offers timezone implementations subclassing the abstract :py:class:`datetime.tzinfo` type. There are classes to handle tzfile format files (usually are in :file:`/etc/localtime`, :file:`/usr/share/zoneinfo`, etc), TZ environment string (in all known formats), given ranges (with help from relative deltas), local machine timezone, fixed offset timezone, and UTC timezone. N) OrderedDict) string_types)_thread)tzname_in_python2_tzinfo) tzrangebaseenfold)_validate_fromutc_inputs) _TzSingleton_TzOffsetFactory) _TzStrFactory)tzwin tzwinlocal)warnc@sbeZdZdZddZddZeddZdd Ze d d Z d d Z dZ ddZ ddZejZdS)tzutca This is a tzinfo object that represents the UTC time zone. **Examples:** .. doctest:: >>> from datetime import * >>> from dateutil.tz import * >>> datetime.now() datetime.datetime(2003, 9, 27, 9, 40, 1, 521290) >>> datetime.now(tzutc()) datetime.datetime(2003, 9, 27, 12, 40, 12, 156379, tzinfo=tzutc()) >>> datetime.now(tzutc()).tzname() 'UTC' .. versionchanged:: 2.7.0 ``tzutc()`` is now a singleton, so the result of ``tzutc()`` will always return the same object. .. doctest:: >>> from dateutil.tz import tzutc, UTC >>> tzutc() is tzutc() True >>> tzutc() is UTC True cCtSNZEROselfdtri/private/var/folders/v1/_jykv66s6qd26_69j1njbrl80000gr/T/pip-target-p1gutpg6/lib/python/dateutil/tz/tz.py utcoffsetJztzutc.utcoffsetcCrrrrrrrdstMrz tzutc.dstcCdS)NUTCrrrrrtznamePsz tzutc.tznamecCr)6 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 Frrrrr is_ambiguousTsztzutc.is_ambiguouscCs|S)z Fast track version of fromutc() returns the original ``dt`` object for any valid :py:class:`datetime.datetime` object. rrrrrfromutcdsz tzutc.fromutccCs0t|ttfs tSt|tpt|to|jtkSr) isinstancertzoffsetNotImplemented_offsetrrotherrrr__eq__ls  z tzutc.__eq__NcC ||k Srrr(rrr__ne__u z tzutc.__ne__cC d|jjSNz%s() __class____name__rrrr__repr__x ztzutc.__repr__)r2 __module__ __qualname____doc__rrrr r"r r#r*__hash__r,r4object __reduce__rrrrr)s   rc@sjeZdZdZddZddZddZedd Ze d d Z d d Z ddZ dZ ddZddZejZdS)r%a1 A simple class for representing a fixed offset from UTC. :param name: The timezone name, to be returned when ``tzname()`` is called. :param offset: The time zone offset in seconds, or (since version 2.6.0, represented as a :py:class:`datetime.timedelta` object). c Cs@||_z|}Wn ttfyYnwtjt|d|_dSNseconds)_name total_seconds TypeErrorAttributeErrordatetime timedelta_get_supported_offsetr')rnameoffsetrrr__init__s ztzoffset.__init__cC|jSrr'rrrrrztzoffset.utcoffsetcCrrrrrrrrrz tzoffset.dstcCrIr)r?rrrrr ztzoffset.tznamecCs ||jSrrJrrrrr#s ztzoffset.fromutccCr)a4 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 Frrrrrr"s ztzoffset.is_ambiguouscCst|tstS|j|jkSr)r$r%r&r'r(rrrr*s  ztzoffset.__eq__NcCr+rrr(rrrr,r-ztzoffset.__ne__cCs"d|jjt|jt|jfS)Nz %s(%s, %s))r1r2reprr?intr'r@r3rrrr4s ztzoffset.__repr__)r2r6r7r8rHrrrr r r#r"r*r9r,r4r:r;rrrrr%s     r%csxeZdZdZfddZddZddZedd Zd d Z d d Z dddZ ddZ dZ ddZddZejZZS)tzlocalzR A :class:`tzinfo` subclass built around the ``time`` timezone functions. csltt|tjtj d|_tjrtjtj d|_ n|j|_ |j |j|_ t |j |_ ttj|_dSr<)superrOrHrCrDtimetimezone _std_offsetdaylightaltzone _dst_offset _dst_savedbool_hasdsttupler _tznamesr3r1rrrHs ztzlocal.__init__cCs(|dur |jr dS||r|jS|jSr)rY_isdstrVrSrrrrrs  ztzlocal.utcoffsetcCs,|dur |jr dS||r|j|jStSr)rYr]rVrSrrrrrrs   z tzlocal.dstcCs|j||Sr)r[r]rrrrr sztzlocal.tznamecCs$||}| o||||jkS)r!) _naive_is_dstrW)rrZ naive_dstrrrr"s ztzlocal.is_ambiguouscCst|}t|tjjSr)_datetime_to_timestamprQ localtimerRtm_isdst)rr timestamprrrr^sztzlocal._naive_is_dstTcCsF|jsdS||}t|dd}||r!|dur|| SdS|S)NFfoldT)rYr^getattrr"_fold)rrZ fold_naiveZdstvalrcrrrr]s    ztzlocal._isdstcCs~t|tr|j|jko|j|jkSt|tr&|j o%|jddvo%|jtkSt|tr=|j o<|jd|j ko<|j|j kSt S)Nr>GMTr) r$rOrSrVrrYr[rr%r?r'r&r(rrrr*.s"       ztzlocal.__eq__NcCr+rrr(rrrr,?r-ztzlocal.__ne__cCr.r/r0r3rrrr4Br5ztzlocal.__repr__)T)r2r6r7r8rHrrrr r"r^r]r*r9r,r4r:r; __classcell__rrr\rrOs     (rOc@sHeZdZgdZddZddZddZdZd d Zd d Z d dZ dS)_ttinfo)rGdeltaisdstabbrisstdisgmt dstoffsetcCs|jD]}t||dqdSr __slots__setattr)rattrrrrrHLs z_ttinfo.__init__cCsNg}|jD]}t||}|dur|d|t|fqd|jjd|fS)Nz%s=%s%s(%s)z, )rprdappendrMr1r2join)rlrrvaluerrrr4Ps  z_ttinfo.__repr__cCsbt|tstS|j|jko0|j|jko0|j|jko0|j|jko0|j|jko0|j|jko0|j |j kSr) r$rhr&rGrirjrkrlrmrnr(rrrr*Xs        z_ttinfo.__eq__NcCr+rrr(rrrr,fr-z_ttinfo.__ne__cCs$i}|jD] }t||d||<q|Sr)rprdrstaterFrrr __getstate__is z_ttinfo.__getstate__cCs(|jD]}||vrt||||qdSrrorxrrr __setstate__os z_ttinfo.__setstate__) r2r6r7rprHr4r*r9r,rzr{rrrrrhHs  rhc@s eZdZdZgdZddZdS)_tzfilezw Lightweight class for holding the relevant transition and time zone information read from binary tzfiles. ) trans_listtrans_list_utc trans_idx ttinfo_list ttinfo_std ttinfo_dst ttinfo_before ttinfo_firstcKs$|jD] }t||||dqdSr)attrsrqget)rkwargsrrrrrrH}s z_tzfile.__init__N)r2r6r7r8rrHrrrrr|us r|cseZdZdZd&fdd ZddZddZd'd d Zd d ZddZ ddZ d&ddZ ddZ ddZ ddZeddZddZdZddZd d!Zd"d#Zd$d%ZZS)(tzfilea 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 `_ for more information. Time zone files can be compiled from the `IANA Time Zone database files `_ with the `zic time zone compiler `_ .. 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 Ncstt|d}t|tr||_t|d}d}n|dur!||_nt|dr+|j|_nt ||_|durX|s:t |}| }| |}Wdn1sLwY| |dSdS)NFrbTrF) rPrrHr$r _filenameopenhasattrrFrM _nullcontext _read_tzfile _set_tzdata)rfileobjfilenameZfile_opened_hereZ file_streamtzobjr\rrrHs&      ztzfile.__init__cCs&tjD] }t|d|t||qdS)z= Set the time zone data of this object from a _tzfile object _N)r|rrqrd)rrrrrrrrs ztzfile._set_tzdatac st|ddkrtd|dtd|d\}}}}}}|r7ttd|||d_ng_|rItd|||_ng_g}t |D]} | td |d qR||} |rs| |d t j |rtd |||} |rtd |||} g_t |D]J} || \} }}t| } t}| |_td |_tj| d|_||_| || d||_|| ko| | d k|_|| ko| | d k|_j |qfddjD_d_d_d_jrYjsjd __nTt |dddD])} j| }js |js |_n js+|jr+|_jr5jr5nq jrCjsCj_jD] }|jsQ|_nqFjd _d}d}d}d}g_t jD]U\} }|j}d }|dur|jr|s||}|s|r|}tj|d|_|}||}|}|dur||kr|j|kr|}|j}|}|}j j| |qit!j_t!j_t!j_S)NZTZifzmagic not foundz>6lz>%dlz>%dBz>lbbz>%dbrr=csg|]}j|qSr)r).0idxoutrr ssz'tzfile._read_tzfile..r)"r|readdecode ValueErrorstructunpacklistr~rrangertseekosSEEK_CURrrErhrGrCrDrnrirjfindrkrlrmrrrrr} enumeraterZ)rrZ ttisgmtcntZ ttisstdcntZleapcntZtimecntZtypecntZcharcntZttinfoirkrlrmgmtoffrjZabbrindttiZlastdstZ lastoffsetZ lastdstoffsetZlastbaseoffsetrGrnZ baseoffsetZ adjustmentrrrrs                     ztzfile._read_tzfileFcCs6|jsdSt|}|r|jn|j}t||}|dS)Nr) _trans_listr_Z_trans_list_utcbisect bisect_right)rrin_utcrbr}rrrr_find_last_transitions  ztzfile._find_last_transitioncCs8|dus |dt|jkr|jS|dkr|jS|j|S)Nrr)lenr _ttinfo_stdZ_ttinfo_before _trans_idx)rrrrr _get_ttinfos  ztzfile._get_ttinfocCs||}||Sr)_resolve_ambiguous_timer)rrrrrr _find_ttinfos  ztzfile._find_ttinfocCsnt|tjs td|j|urtd|j|dd}||}|tj|jd}|j ||d}t |t |dS)a 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. z&fromutc() requires a datetime argumentzdt.tzinfo is not selfT)rr=)rrc) r$rCrAtzinforrrrDrGr"r rN)rrrrZdt_outrcrrrr#s   ztzfile.fromutccCsd|dur ||}t|}||}|dus|dkrdS||dj|j}|j|}|||kS)r!NrFr)rr_rrGr)rrrrbrZodttrrrr" s    ztzfile.is_ambiguouscCsF||}||}|dus|dkr|St| o|||}||S)Nr)rrerNr")rrrreZ idx_offsetrrrr(s  ztzfile._resolve_ambiguous_timecCs"|durdS|js tS||jSr)rrrrirrrrr5s  ztzfile.utcoffsetcCs0|durdS|js tS||}|jstS|jSr)Z _ttinfo_dstrrrjrn)rrrrrrr>s z tzfile.dstcCs|jr|dur dS||jSr)rrrkrrrrr Ns z tzfile.tznamecCs2t|tstS|j|jko|j|jko|j|jkSr)r$rr&rrZ _ttinfo_listr(rrrr*Ts    z tzfile.__eq__cCr+rrr(rrrr,]r-z tzfile.__ne__cCd|jjt|jfSNrs)r1r2rMrr3rrrr4`ztzfile.__repr__cCs |dSr) __reduce_ex__r3rrrr;cr-ztzfile.__reduce__cCs|jd|jf|jfSr)r1r__dict__)rprotocolrrrrfsztzfile.__reduce_ex__rF)r2r6r7r8rHrrrrrr#r"rrrrr r*r9r,r4r;rrgrrr\rrs,G a  $   rc@s<eZdZdZ   d ddZddZddZed d ZdS) tzrangea[ The ``tzrange`` object is a time zone specified by a set of offsets and abbreviations, equivalent to the way the ``TZ`` variable can be specified in POSIX-like systems, but using Python delta objects to specify DST start, end and offsets. :param stdabbr: The abbreviation for standard time (e.g. ``'EST'``). :param stdoffset: An integer or :class:`datetime.timedelta` object or equivalent specifying the base offset from UTC. If unspecified, +00:00 is used. :param 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``, ``start`` and ``end`` is 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. :param dstoffset: A an integer or :class:`datetime.timedelta` object 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. :param start: A :class:`relativedelta.relativedelta` object 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. :param end: A :class:`relativedelta.relativedelta` object or equivalent representing the time and time of year that daylight savings time ends, with the same specification method as in ``start``. 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:** .. testsetup:: tzrange from dateutil.tz import tzrange, tzstr .. doctest:: tzrange >>> 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 Nc Cs8ddlma||_||_z|}Wn ttfyYnwz|}Wn ttfy/Ynw|duri iQr)rrrrweekrZydayZjydayrrQrVrSr>days)rxrrrrirrrrWs>               z tzstr._deltacCrrr1r2rMrr3rrrr4rztzstr.__repr__Nr)r)r2r6r7r8rHrr4rrrrr s  ) )rc@seZdZ dddZdS)_tzicalvtzcompNcCs@tj|d|_tj|d|_|j|j|_||_||_||_dSr<)rCrD tzoffsetfrom tzoffsetto tzoffsetdiffrjr rrule)rrrrjr rrrrrHs  z_tzicalvtzcomp.__init__)NN)r2r6r7rHrrrrrsrcsZeZdZgffdd ZddZddZddZd d Zed d Z d dZ e j Z Z S) _tzicalvtzcs4tt|||_||_g|_g|_t|_ dSr) rPrrH_tzid_comps _cachedate _cachecompr allocate_lock _cache_lock)rtzidcompsr\rrrHs z_tzicalvtz.__init__cCsbt|jdkr |jdS|jdd}z$|j|j|j|||fWdWS1s0wYWn ty?Ynwd}d}|jD]}| ||}|r[|rW||kr[|}|}qG|so|jD] }|j sj|}nqa|d}|j5|j d|||f|j d|t|jdkr|j |j Wd|SWd|S1swY|S)Nrrrr) rrreplacerrrindexrer _find_compdtrjinsertpop)rrZ lastcompdtZlastcompcompcompdtrrr _find_compsP    &        z_tzicalvtz._find_compcCs2|jtkr||r||j8}|jj|dd}|S)NT)inc)rrrerbefore)rrrrrrrrs z_tzicalvtz._find_compdtcCs|durdS||jSr)rrrrrrrs z_tzicalvtz.utcoffsetcCs||}|jr |jStSr)rrjrr)rrrrrrrs z_tzicalvtz.dstcCs ||jSr)rr rrrrr s z_tzicalvtz.tznamecCsdt|jS)Nz)rMrr3rrrr4sz_tzicalvtz.__repr__)r2r6r7rHrrrrrr r4r:r;rgrrr\rrs - rc@sBeZdZdZddZddZdddZd d Zd d Zd dZ dS)tzicala[ This object is designed to parse an iCalendar-style ``VTIMEZONE`` structure as set out in `RFC 5545`_ Section 4.6.5 into one or more `tzinfo` objects. :param `fileobj`: A file or stream in iCalendar format, which should be UTF-8 encoded with CRLF endings. .. _`RFC 5545`: https://tools.ietf.org/html/rfc5545 cCsddlmat|tr||_t|d}n t|dt||_t|}i|_ |}| | WddS1s9wYdS)Nr)rrrF) rrr$rrrrdrMr_vtz _parse_rfcr)rrZfobjrrrrHs   "ztzical.__init__cCst|jS)z? Retrieves the available time zones as a list. )rrkeysr3rrrr sz tzical.keysNcCsN|dur!t|jdkrtdt|jdkrtdtt|j}|j|S)a Retrieve a :py:class:`datetime.tzinfo` object by its ``tzid``. :param tzid: If there is exactly one time zone available, omitting ``tzid`` or passing :py:const:`None` value returns it. Otherwise a valid key (which can be retrieved from :func:`keys`) is required. :raises ValueError: Raised if ``tzid`` is not specified but there are either more or fewer than 1 zone defined. :returns: Returns either a :py:class:`datetime.tzinfo` object representing the relevant time zone or :py:const:`None` if the ``tzid`` was not found. Nrzno timezones definedrz more than one timezone available)rrrnextiterr)rrrrrrs z tzical.getcCs|}|s td|ddvrd|ddk}|dd}nd}t|dkr=t|ddd t|ddd |St|d krat|ddd t|ddd t|dd|Std |) Nz empty offsetr)+-)rrr rrri<rzinvalid offset: )striprrrN)rrsignalrrr _parse_offset"s  , < ztzical._parse_offsetcCsP|}|s tdd}|t|krD||}|s||=n |dkr:|ddkr:||d|dd7<||=n|d7}|t|ksd}g}d}d}|D]V}|sTqN|dd\} } | d} | sgtd| d} | dd} |r| d kr| d vrntd | | }d} d} d}g}d}qN| d kr| d kr|rtd||std|stdt|||j|<d}qN| |kr| std| durtd|durtdd}|rtj d |dddd}t | ||dk||}| |d}qNtd| |rv| dkr| D]}|dkrd|}t|q| |d} qN| dvr)| |qN| dkrA| r;td| | df| | } qN| dkrW| rQtd| d| | }qN| d krj| rgtd!| d| }qN| d"krpqNtd#| | d$kr| rtd%| d| }qN| d&vrqNtd#| | d kr| d krd}g}d}qNdS)'Nz empty stringr rF:;zempty property nameZBEGIN)STANDARDDAYLIGHTzunknown component: ZENDZ VTIMEZONEzcomponent not closed: zmandatory TZID not foundz at least one component is neededzmandatory DTSTART not foundz mandatory TZOFFSETFROM not found T) compatibleZignoretzcacherzinvalid component end: ZDTSTARTzVALUE=DATE-TIMEz(Unsupported DTSTART param in VTIMEZONE: )ZRRULEZRDATEZEXRULEZEXDATEZ TZOFFSETFROMzunsupported %s parm: %s Z TZOFFSETTOzunsupported TZOFFSETTO parm: ZTZNAMEzunsupported TZNAME parm: COMMENTzunsupported property: ZTZIDzunsupported TZID parm: )ZTZURLz LAST-MODIFIEDr) splitlinesrrrstripsplitupperrrrZrrulestrrurrtr)rrlinesrlinerrZinvtzcomptyperFrwZparmsZ founddtstartrrZ rrulelinesr rrrZparmmsgrrrr 2s                               ztzical._parse_rfccCrrrr3rrrr4rztzical.__repr__r) r2r6r7r8rHr rrr r4rrrrrs   }rwin32z/etc/localtimer`)z/usr/share/zoneinfoz/usr/lib/zoneinfoz/usr/share/lib/zoneinfoz /etc/zoneinfocs2tftdur tf7Gfdddt}|S)NcsDeZdZdZddZd fdd ZddZd d Zed d d Z dS)z__get_gettz..GettzFunca Retrieve a time zone object from a string representation This function is intended to retrieve the :py:class:`tzinfo` subclass that best represents the time zone that would be used if a POSIX `TZ variable`_ were set to the same value. If no argument or an empty string is passed to ``gettz``, local time is returned: .. code-block:: python3 >>> gettz() tzfile('/etc/localtime') This function is also the preferred way to map IANA tz database keys to :class:`tzfile` objects: .. code-block:: python3 >>> gettz('Pacific/Kiritimati') tzfile('/usr/share/zoneinfo/Pacific/Kiritimati') On Windows, the standard is extended to include the Windows-specific zone names provided by the operating system: .. code-block:: python3 >>> gettz('Egypt Standard Time') tzwin('Egypt Standard Time') Passing a GNU ``TZ`` style string time zone specification returns a :class:`tzstr` object: .. code-block:: python3 >>> gettz('AEST-10AEDT-11,M10.1.0/2,M4.1.0/3') tzstr('AEST-10AEDT-11,M10.1.0/2,M4.1.0/3') :param name: A time zone name (IANA, or, on Windows, Windows keys), location of a ``tzfile(5)`` zoneinfo file or ``TZ`` variable style time zone specifier. An empty string, no argument or ``None`` is interpreted as local time. :return: Returns an instance of one of ``dateutil``'s :py:class:`tzinfo` subclasses. .. versionchanged:: 2.7.0 After version 2.7.0, any two calls to ``gettz`` using the same input strings will return the same object: .. code-block:: python3 >>> tz.gettz('America/Chicago') is tz.gettz('America/Chicago') True In addition to improving performance, this ensures that `"same zone" semantics`_ are used for datetimes in the same zone. .. _`TZ variable`: https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html .. _`"same zone" semantics`: https://blog.ganssle.io/articles/2018/02/aware-datetime-arithmetic.html cSs&t|_d|_t|_t|_dS)Nr) weakrefWeakValueDictionary_GettzFunc__instances_GettzFunc__strong_cache_sizer_GettzFunc__strong_cacherrrr3rrrrH s z'__get_gettz..GettzFunc.__init__Ncs|jW|j|d}|dur1|j|d}|dus(t|s(|dus(||j|<n |WdS|j|||j|<t|j|jkrR|jj ddWd|SWd|S1s]wY|S)N)rFFlast) rr(rnocacher$r*rrr)popitem)rrFrvZtzlocal_classesrr__call__s,    z'__get_gettz..GettzFunc.__call__cSsl|j)||_t|j|kr$|jjddt|j|ksWddSWddS1s/wYdS)NFr+)rr)rr*r.)rsizerrrset_cache_size+s"z-__get_gettz..GettzFunc.set_cache_sizecSs@|jt|_|jWddS1swYdSr)rr&r'r(r*clearr3rrr cache_clear1s  "z*__get_gettz..GettzFunc.cache_clearc Ssrd}|sztjd}Wn tyYnw|dus|dvr_tD]:}tj|s>|}tD]}tj||}tj|r<nq+qtj|rYzt |}W|St t t fyXYqwqt }|Sz |drk|dd}Wn#ty}zt|trd}tt||nWYd}~nd}~wwtj|rtj|rt |}|Sd}|StD]0}tj||}tj|s|dd}tj|sqzt |}W|St t t fyYqwd}tdurzt|}Wn ttfyd}Ynw|sd d lm}||}|s7|D]}|d vr#zt|}W|St y"Y|Swq|d vr.t}|S|tjvr7t }|S) zA non-cached version of gettzNZTZ)rrrz'gettz argument should be str, not bytesrrr)get_zonefile_instance 0123456789r)renvironKeyErrorTZFILESpathisabsTZPATHSruisfilerIOErrorOSErrorrrO startswithrAr$bytessix raise_fromrrZ WindowsErrorUnicodeEncodeErrorZdateutil.zoneinfor7rrrrQr ) rFtzfilepathrr<eZnew_msgr7crrrr-6s    >:      -+   !       z&__get_gettz..GettzFunc.nocacher) r2r6r7r8rHr1r3r5 staticmethodr-rr0rr GettzFuncsErL)rOrr:)rLrr0r __get_gettzs  JrMcCsX|dur|jdur td|j}|jdd}|j|dt|}|jdd}||kS)a Given a datetime and a time zone, determine whether or not a given datetime would fall in a gap. :param dt: A :class:`datetime.datetime` (whose time zone will be ignored if ``tz`` is provided.) :param tz: A :class:`datetime.tzinfo` with support for the ``fold`` attribute. If ``None`` or not provided, the datetime's own time zone will be used. :return: Returns a boolean value whether or not the "wall time" exists in ``tz``. .. versionadded:: 2.7.0 N,Datetime is naive and no time zone provided.r)rrr astimezoner)rrGZdt_rtrrrdatetime_existss   rPcCs|dur|jdur td|j}t|dd}|dur*z||WSty)Ynw|j|d}t|dd}t|dd}||k}||k}|oO| S)a\ 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). :param dt: A :class:`datetime.datetime` (whose time zone will be ignored if ``tz`` is provided.) :param tz: A :class:`datetime.tzinfo` with support for the ``fold`` attribute. If ``None`` or not provided, the datetime's own time zone will be used. :return: Returns a boolean value whether or not the "wall time" is ambiguous in ``tz``. .. versionadded:: 2.6.0 NrNr"rrrr) rrrdr" Exceptionrr rr)rrGZis_ambiguous_fnZwall_0Zwall_1Z same_offsetZsame_dstrrrdatetime_ambiguouss"        rRcCsJ|jdur#t|s#|tjdd}|tjdd}|||7}|S)aZ Given a datetime that may be imaginary, return an existing datetime. This function assumes that an imaginary datetime represents what the wall time would be in a zone had the offset transition not occurred, so it will always fall forward by the transition's change in offset. .. doctest:: >>> from dateutil import tz >>> from datetime import datetime >>> NYC = tz.gettz('America/New_York') >>> print(tz.resolve_imaginary(datetime(2017, 3, 12, 2, 30, tzinfo=NYC))) 2017-03-12 03:30:00-04:00 >>> KIR = tz.gettz('Pacific/Kiritimati') >>> print(tz.resolve_imaginary(datetime(1995, 1, 1, 12, 30, tzinfo=KIR))) 1995-01-02 12:30:00+14:00 As a note, :func:`datetime.astimezone` is guaranteed to produce a valid, existing datetime, so a round-trip to and from UTC is sufficient to get an extant datetime, however, this generally "falls back" to an earlier time rather than falling forward to the STD side (though no guarantees are made about this behavior). :param dt: A :class:`datetime.datetime` which may or may not exist. :return: Returns an existing :class:`datetime.datetime`. If ``dt`` was not imaginary, the datetime returned is guaranteed to be the same object passed to the function. .. versionadded:: 2.7.0 Nrr)rrPrCrDr)rZ curr_offset old_offsetrrrresolve_imaginarys $ rTcCs|jddtS)z Convert a :class:`datetime.datetime` object to an epoch timestamp in seconds since January 1, 1970, ignoring the time zone. Nr)rEPOCHr@)rrrrr_sr_)rcCs|Srr) second_offsetrrrrErrEcCs|}d|dd}|S)Nrr)rWrSZcalculated_offsetrrrrEs) nullcontextc@s(eZdZdZddZddZddZdS) rzj Class for wrapping contexts so that they are passed through in a with statement. cCs ||_dSrcontext)rr[rrrrH0r-z_nullcontext.__init__cCrIrrZr3rrr __enter__3rKz_nullcontext.__enter__cOsdSrr)argsrrrr__exit__6rz_nullcontext.__exit__N)r2r6r7r8rHr\r^rrrrr+s  rr)Ar8rCrrQsysrrr& collectionsrrDrZ six.movesr_commonrrrr r Z _factoriesr r r winrr ImportErrorwarningsrrDrutcfromtimestamprU toordinalZ EPOCHORDINAL add_metaclassrrrr%rOr:rhr|rrrrrrplatformr;r>rMZgettzrPrRrTr_ version_inforE contextlibrYrrrrrs          WD- k#w V O R  "..