
    	hǥ                    8   S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
Jr  SSKJrJrJrJrJrJrJrJrJrJr  SSKr\(       a  SSKJr  SSKJr  SSKJr  S	r\" S
SS9r\" S5      r \" S5      r!\RD                  " \#5      r$ " S S5      r% " S S\%5      r& " S S\%5      r' " S S\'5      r( " S S\(5      r) " S S\RT                  5      r+ " S S\\,\,4   5      r-S%S jr.S%S jr/S&S jr0 " S  S!5      r1\1" 5       r2S'S" jr3 " S# S$\\\!4   5      r4g)(uU#  
win32timezone:
    Module for handling datetime.tzinfo time zones using the windows
registry for time zone information.  The time zone names are dependent
on the registry entries defined by the operating system.

    This module may be tested using the doctest module.

    Written by Jason R. Coombs (jaraco@jaraco.com).
    Copyright © 2003-2012.
    All Rights Reserved.

    This module is licensed for use in Mark Hammond's pywin32
library under the same terms as the pywin32 library.

    To use this time zone module with the datetime module, simply pass
the TimeZoneInfo object to the datetime constructor.  For example,

>>> import win32timezone, datetime
>>> assert 'Mountain Standard Time' in win32timezone.TimeZoneInfo.get_sorted_time_zone_names()
>>> MST = win32timezone.TimeZoneInfo('Mountain Standard Time')
>>> now = datetime.datetime.now(MST)

    The now object is now a time-zone aware object, and daylight savings-
aware methods may be called on it.

>>> now.utcoffset() in (datetime.timedelta(-1, 61200), datetime.timedelta(-1, 64800))
True

(note that the result of utcoffset call will be different based on when now was
generated, unless standard time is always used)

>>> now = datetime.datetime.now(win32timezone.TimeZoneInfo('Mountain Standard Time', True))
>>> now.utcoffset()
datetime.timedelta(days=-1, seconds=61200)

>>> aug2 = datetime.datetime(2003, 8, 2, tzinfo = MST)
>>> tuple(aug2.utctimetuple())
(2003, 8, 2, 6, 0, 0, 5, 214, 0)
>>> nov2 = datetime.datetime(2003, 11, 25, tzinfo = MST)
>>> tuple(nov2.utctimetuple())
(2003, 11, 25, 7, 0, 0, 1, 329, 0)

To convert from one timezone to another, just use the astimezone method.

>>> aug2.isoformat()
'2003-08-02T00:00:00-06:00'
>>> aug2est = aug2.astimezone(win32timezone.TimeZoneInfo('Eastern Standard Time'))
>>> aug2est.isoformat()
'2003-08-02T02:00:00-04:00'

calling the displayName member will return the display name as set in the
registry.

>>> est = win32timezone.TimeZoneInfo('Eastern Standard Time')
>>> str(est.displayName)
'(UTC-05:00) Eastern Time (US & Canada)'

>>> gmt = win32timezone.TimeZoneInfo('GMT Standard Time', True)
>>> str(gmt.displayName)
'(UTC+00:00) Dublin, Edinburgh, Lisbon, London'

To get the complete list of available time zone keys,
>>> zones = win32timezone.TimeZoneInfo.get_all_time_zones()

If you want to get them in an order that's sorted longitudinally
>>> zones = win32timezone.TimeZoneInfo.get_sorted_time_zones()

TimeZoneInfo now supports being pickled and comparison
>>> import pickle
>>> tz = win32timezone.TimeZoneInfo('China Standard Time')
>>> tz == pickle.loads(pickle.dumps(tz))
True

It's possible to construct a TimeZoneInfo from a TimeZoneDescription
including the currently-defined zone.
>>> code, info = win32timezone.TimeZoneDefinition.current()
>>> tz = win32timezone.TimeZoneInfo(info, not code)
>>> tz == pickle.loads(pickle.dumps(tz))
True

Although it's easier to use TimeZoneInfo.local() to get the local info
>>> tz == TimeZoneInfo.local()
True

>>> aest = win32timezone.TimeZoneInfo('AUS Eastern Standard Time')
>>> est = win32timezone.TimeZoneInfo('E. Australia Standard Time')
>>> dt = datetime.datetime(2006, 11, 11, 1, 0, 0, tzinfo = aest)
>>> estdt = dt.astimezone(est)
>>> estdt.strftime('%Y-%m-%d %H:%M:%S')
'2006-11-11 00:00:00'

>>> dt = datetime.datetime(2007, 1, 12, 1, 0, 0, tzinfo = aest)
>>> estdt = dt.astimezone(est)
>>> estdt.strftime('%Y-%m-%d %H:%M:%S')
'2007-01-12 00:00:00'

>>> dt = datetime.datetime(2007, 6, 13, 1, 0, 0, tzinfo = aest)
>>> estdt = dt.astimezone(est)
>>> estdt.strftime('%Y-%m-%d %H:%M:%S')
'2007-06-13 01:00:00'

Microsoft now has a patch for handling time zones in 2007 (see
https://learn.microsoft.com/en-us/troubleshoot/windows-client/system-management-components/daylight-saving-time-help-support)

As a result, patched systems will give an incorrect result for
dates prior to the designated year except for Vista and its
successors, which have dynamic time zone support.
>>> nov2_pre_change = datetime.datetime(2003, 11, 2, tzinfo = MST)
>>> old_response = (2003, 11, 2, 7, 0, 0, 6, 306, 0)
>>> incorrect_patch_response = (2003, 11, 2, 6, 0, 0, 6, 306, 0)
>>> pre_response = nov2_pre_change.utctimetuple()
>>> pre_response in (old_response, incorrect_patch_response)
True

Furthermore, unpatched systems pre-Vista will give an incorrect
result for dates after 2007.
>>> nov2_post_change = datetime.datetime(2007, 11, 2, tzinfo = MST)
>>> incorrect_unpatched_response = (2007, 11, 2, 7, 0, 0, 4, 306, 0)
>>> new_response = (2007, 11, 2, 6, 0, 0, 4, 306, 0)
>>> post_response = nov2_post_change.utctimetuple()
>>> post_response in (new_response, incorrect_unpatched_response)
True


There is a function you can call to get some capabilities of the time
zone data.
>>> caps = GetTZCapabilities()
>>> isinstance(caps, dict)
True
>>> 'MissingTZPatch' in caps
True
>>> 'DynamicTZSupport' in caps
True

>>> both_dates_correct = (pre_response == old_response and post_response == new_response)
>>> old_dates_wrong = (pre_response == incorrect_patch_response)
>>> new_dates_wrong = (post_response == incorrect_unpatched_response)

>>> caps['DynamicTZSupport'] == both_dates_correct
True

>>> (not caps['DynamicTZSupport'] and caps['MissingTZPatch']) == new_dates_wrong
True

>>> (not caps['DynamicTZSupport'] and not caps['MissingTZPatch']) == old_dates_wrong
True

This test helps ensure language support for unicode characters
>>> x = TIME_ZONE_INFORMATION(0, 'français')


Test conversion from one time zone to another at a DST boundary
===============================================================

>>> tz_hi = TimeZoneInfo('Hawaiian Standard Time')
>>> tz_pac = TimeZoneInfo('Pacific Standard Time')
>>> time_before = datetime.datetime(2011, 11, 5, 15, 59, 59, tzinfo=tz_hi)
>>> tz_hi.utcoffset(time_before)
datetime.timedelta(days=-1, seconds=50400)
>>> tz_hi.dst(time_before)
datetime.timedelta(0)

Hawaii doesn't need dynamic TZ info
>>> getattr(tz_hi, 'dynamicInfo', None)

Here's a time that gave some trouble as reported in #3523104
because one minute later, the equivalent UTC time changes from DST
in the U.S.
>>> dt_hi = datetime.datetime(2011, 11, 5, 15, 59, 59, 0, tzinfo=tz_hi)
>>> dt_hi.timetuple()
time.struct_time(tm_year=2011, tm_mon=11, tm_mday=5, tm_hour=15, tm_min=59, tm_sec=59, tm_wday=5, tm_yday=309, tm_isdst=0)
>>> dt_hi.utctimetuple()
time.struct_time(tm_year=2011, tm_mon=11, tm_mday=6, tm_hour=1, tm_min=59, tm_sec=59, tm_wday=6, tm_yday=310, tm_isdst=0)

Convert the time to pacific time.
>>> dt_pac = dt_hi.astimezone(tz_pac)
>>> dt_pac.timetuple()
time.struct_time(tm_year=2011, tm_mon=11, tm_mday=5, tm_hour=18, tm_min=59, tm_sec=59, tm_wday=5, tm_yday=309, tm_isdst=1)

Notice that the UTC time is almost 2am.
>>> dt_pac.utctimetuple()
time.struct_time(tm_year=2011, tm_mon=11, tm_mday=6, tm_hour=1, tm_min=59, tm_sec=59, tm_wday=6, tm_yday=310, tm_isdst=0)

Now do the same tests one minute later in Hawaii.
>>> time_after = datetime.datetime(2011, 11, 5, 16, 0, 0, 0, tzinfo=tz_hi)
>>> tz_hi.utcoffset(time_after)
datetime.timedelta(days=-1, seconds=50400)
>>> tz_hi.dst(time_before)
datetime.timedelta(0)

>>> dt_hi = datetime.datetime(2011, 11, 5, 16, 0, 0, 0, tzinfo=tz_hi)
>>> print(dt_hi.timetuple())
time.struct_time(tm_year=2011, tm_mon=11, tm_mday=5, tm_hour=16, tm_min=0, tm_sec=0, tm_wday=5, tm_yday=309, tm_isdst=0)
>>> print(dt_hi.utctimetuple())
time.struct_time(tm_year=2011, tm_mon=11, tm_mday=6, tm_hour=2, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=310, tm_isdst=0)

According to the docs, this is what astimezone does.
>>> utc = (dt_hi - dt_hi.utcoffset()).replace(tzinfo=tz_pac)
>>> utc
datetime.datetime(2011, 11, 6, 2, 0, tzinfo=TimeZoneInfo('Pacific Standard Time'))
>>> tz_pac.fromutc(utc) == dt_hi.astimezone(tz_pac)
True
>>> tz_pac.fromutc(utc)
datetime.datetime(2011, 11, 5, 19, 0, tzinfo=TimeZoneInfo('Pacific Standard Time'))

Make sure the converted time is correct.
>>> dt_pac = dt_hi.astimezone(tz_pac)
>>> dt_pac.timetuple()
time.struct_time(tm_year=2011, tm_mon=11, tm_mday=5, tm_hour=19, tm_min=0, tm_sec=0, tm_wday=5, tm_yday=309, tm_isdst=1)
>>> dt_pac.utctimetuple()
time.struct_time(tm_year=2011, tm_mon=11, tm_mday=6, tm_hour=2, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=310, tm_isdst=0)

Check some internal methods
>>> tz_pac._getStandardBias(datetime.datetime(2011, 1, 1))
datetime.timedelta(seconds=28800)
>>> tz_pac._getDaylightBias(datetime.datetime(2011, 1, 1))
datetime.timedelta(seconds=25200)

Test the offsets
>>> offset = tz_pac.utcoffset(datetime.datetime(2011, 11, 6, 2, 0))
>>> offset == datetime.timedelta(hours=-8)
True
>>> dst_offset = tz_pac.dst(datetime.datetime(2011, 11, 6, 2, 0) + offset)
>>> dst_offset == datetime.timedelta(hours=1)
True
>>> (offset + dst_offset) == datetime.timedelta(hours=-7)
True


Test offsets that occur right at the DST changeover
>>> datetime.datetime.utcfromtimestamp(1320570000).replace(
...     tzinfo=TimeZoneInfo.utc()).astimezone(tz_pac)
datetime.datetime(2011, 11, 6, 1, 0, tzinfo=TimeZoneInfo('Pacific Standard Time'))

    )annotationsN)count)
TYPE_CHECKINGAnyCallableClassVarDict	GeneratorIterableMappingTypeVaroverload)_SupportsComparison)SupportsKeysAndGetItem)Selfz#Jason R. Coombs <jaraco@jaraco.com>_RangeMapKTr   )bound_T_VTc                  L    \ rS rSr% / rS\S'   S
S jrSS jrSS jrSS jr	Sr
g	)_SimpleStructi  z ClassVar[list[tuple[str, type]]]_fields_c                2   [        U R                  5       H~  u  nu  pES nU[        U5      :  a  X   nXB;   a  X$   nUb  [        U[        5      (       d  U4nOSn[        U5      S:X  a  [        US   U5      (       a  US   nOU" U6 n[        XU5        M     g )N    r   )	enumerater   len
isinstancetuplesetattr)selfargskwinametypdef_argdef_vals           jC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\win32/lib/win32timezone.py__init___SimpleStruct.__init__  s    '6NA{G3t9}'z("!'511&jG7|q Z
C%@%@ "!*w-D(# 7    c                J    U R                    Vs/ s H  oS   PM	     sn$ s  snf )Nr   )r   )r!   fs     r)   field_names_SimpleStruct.field_names0  s     "mm,m!m,,,s    c                    [        US5      (       d  gU R                  UR                  :w  a  gU R                   H  u  p#[        X5      [        X5      :w  d  M    g   g)Nr   FT)hasattrr   getattr)r!   otherr%   _s       r)   __eq___SimpleStruct.__eq__3  sO    uj))==ENN*}}GDt"ge&:: % r,   c                .    U R                  U5      (       + $ N)r6   r!   r4   s     r)   __ne___SimpleStruct.__ne__=  s    ;;u%%%r,   r   NreturnNoner>   z	list[str])r>   boolr4   objectr>   rA   )__name__
__module____qualname____firstlineno__r   __annotations__r*   r/   r6   r;   __static_attributes__r   r,   r)   r   r     s!    13H.3)(-&r,   r   c            	      H    \ rS rSrS\4S\4S\4S\4S\4S\4S\4S	\4/rS
rg)
SYSTEMTIMEiA  yearmonthday_of_weekdayhourminutesecondmillisecondr   N)rD   rE   rF   rG   intr   rI   r   r,   r)   rK   rK   A  sC    		#				3	3		Hr,   rK   c                  B    \ rS rSrS\4S\4S\4S\4S\4S\4S\4/rS	rg
)TIME_ZONE_INFORMATIONiN  biasstandard_namestandard_startstandard_biasdaylight_namedaylight_startdaylight_biasr   N)	rD   rE   rF   rG   rT   strrK   r   rI   r   r,   r)   rV   rV   N  s@    		#	:&	#	#	:&	#Hr,   rV   c                  >    \ rS rSr\R
                  S\4S\4/-   rSrg)DYNAMIC_TIME_ZONE_INFORMATIONiZ  key_namedynamic_daylight_time_disabledr   N)	rD   rE   rF   rG   rV   r   r^   rA   rI   r   r,   r)   r`   r`   Z  s'    $--	S	)401 Hr,   r`   c                  
  ^  \ rS rSr% SrSU 4S jjr    SU 4S jjrSU 4S jjr\(       a#  S\	S'   S\	S	'   S
\	S'   S\	S'   S\	S'   S
\	S'   S\	S'   SU 4S jjr
\S 5       rSS jrSS jrSS jrSS jr\SS j5       rSrU =r$ )TimeZoneDefinitionia  z
A time zone definition class based on the win32
DYNAMIC_TIME_ZONE_INFORMATION structure.

Describes a bias against UTC (bias), and two dates at which a separate
additional bias applies (standard_bias and daylight_bias).
c                  >  [         TU ]  " U0 UD6  g! [        [        4 a     Of = f U R                  " U0 UD6  g! [         a     Of = f U R
                  " U0 UD6  g! [         a     Of = f[        SU R                   35      e)a  
>>> test_args = [1] * 44

Try to construct a TimeZoneDefinition from:

a) [DYNAMIC_]TIME_ZONE_INFORMATION args
>>> TimeZoneDefinition(*test_args).bias
datetime.timedelta(seconds=60)

b) another TimeZoneDefinition or [DYNAMIC_]TIME_ZONE_INFORMATION
>>> TimeZoneDefinition(TimeZoneDefinition(*test_args)).bias
datetime.timedelta(seconds=60)
>>> TimeZoneDefinition(DYNAMIC_TIME_ZONE_INFORMATION(*test_args)).bias
datetime.timedelta(seconds=60)
>>> TimeZoneDefinition(TIME_ZONE_INFORMATION(*test_args)).bias
datetime.timedelta(seconds=60)

c) a byte structure (using _from_bytes)
>>> TimeZoneDefinition(bytes(test_args)).bias
datetime.timedelta(days=11696, seconds=46140)
NzInvalid arguments for )superr*   	TypeError
ValueError$_TimeZoneDefinition__init_from_other$_TimeZoneDefinition__init_from_bytes	__class__)r!   r"   kwargsrk   s      r)   r*   TimeZoneDefinition.__init__j  s    ,	Gd-f-:& 			""D3F3 			""D3F3 		 00@ABBs-    ''> 
A
AA" "
A/.A/c                   > Sn[         R                  " Xa5      nUS S u  pn
[        USS 6 n[        USS 6 n[        TU ]  UUUU	UUU
UU5	        g )N3l8h8h         )structunpackrK   rf   r*   )r!   bytesrX   r[   ra   daylight_disabledformat
componentsrW   rZ   r]   rY   r\   rk   s                r)   __init_from_bytes$TimeZoneDefinition.__init_from_bytes  sr     ]]61
-7^*]#Z"%56#Z2%67
	
r,   c                   > [        U[        5      (       d  [        S5      eUR                  5        H"  n[        [        U]  U5      n[        XU5        M$     g )NzNot a TIME_ZONE_INFORMATION)r   rV   rg   r/   rf   __getattribute__r    )r!   r4   r%   valuerk   s       r)   __init_from_other$TimeZoneDefinition.__init_from_other  sL    %!6779::%%'D/HNED& (r,   datetime.timedeltarW   r^   rX   rK   rY   rZ   r[   r\   r]   c                Z   > [         TU ]  U5      nSU;   a  [        R                  " US9nU$ )NrW   )minutes)rf   r|   datetime	timedelta)r!   attrr}   rk   s      r)   r|   #TimeZoneDefinition.__getattribute__  s.    (.T>&&u5Er,   c                >    [         R                  " S5      u  pX" U6 4$ )z+Windows Platform SDK GetTimeZoneInformationT)win32apiGetTimeZoneInformation)clscodetzis      r)   currentTimeZoneDefinition.current  s$     33D9	S#Yr,   c                p   ^  [        U 4S jT R                   5       5      n[        R                  " U5        g )Nc              3  @   >#    U  H  u  p[        TU5      v   M     g 7fr9   )r3   ).0ntr!   s      r)   	<genexpr>)TimeZoneDefinition.set.<locals>.<genexpr>  s     ?GD!$$s   )r   r   r   SetTimeZoneInformationr!   r   s   ` r)   setTimeZoneDefinition.set  s%    ???'',r,   c                $    U R                  U 5      $ r9   rk   r!   s    r)   copyTimeZoneDefinition.copy  s    ~~d##r,   c                8    U R                  XR                  5      $ r9   )_locate_dayr\   r!   rL   s     r)   locate_daylight_start(TimeZoneDefinition.locate_daylight_start      &9&9::r,   c                8    U R                  XR                  5      $ r9   )r   rY   r   s     r)   locate_standard_start(TimeZoneDefinition.locate_standard_start  r   r,   c           	        UR                   S-   S-  nUR                  nUS-
  S-  S-   n[        R                  " U UR                  UUR                  UR
                  UR                  UR                  5      nX%R                  5       -
  S-  nU[        R                  " U5      -  nUR                  UR                  S-   :X  a6  U[        R                  " SS9-  nUR                  UR                  S-   :X  a  M6  U$ )ao  
Takes a SYSTEMTIME object, such as retrieved from a TIME_ZONE_INFORMATION
structure or call to GetTimeZoneInformation and interprets it based on the given
year to identify the actual day.

This method is necessary because the SYSTEMTIME structure refers to a day by its
day of the week and week of the month (e.g. 4th saturday in March).

>>> SATURDAY = 6
>>> MARCH = 3
>>> st = SYSTEMTIME(2000, MARCH, SATURDAY, 4, 0, 0, 0, 0)

# according to my calendar, the 4th Saturday in March in 2009 was the 28th
>>> expected_date = datetime.datetime(2009, 3, 28)
>>> TimeZoneDefinition._locate_day(2009, st) == expected_date
True
      r   )weeks)
rN   rO   r   rM   rP   rQ   rR   rS   weekdayr   )rL   cutofftarget_weekdayweek_of_monthrO   result
days_to_gos          r)   r   TimeZoneDefinition._locate_day  s    ( !,,q0A5 

q A%)""LLKKMMMM
 %~~'771<
($$Z00 llfllQ..h((q11F llfllQ..r,   r   r=   ) r   r   F)r4   rV   r>   r?   )r   r^   r>   r   r>   r   r>   datetime.datetime)rD   rE   rF   rG   __doc__r*   rj   ri   r   rH   r|   classmethodr   r   r   r   r   staticmethodr   rI   __classcell__r   s   @r)   rd   rd   a  s    (CZ 
2'   ""))""))  
-$;; , ,r,   rd   c                     \ rS rSr% SrSr S)     S*S jjrS+S jrS,S jrS-S jr	S.S jr
S-S	 jrS/S
 jrS/S jr\S0S j5       r\S1S j5       rS2S jrS3S jrS rS r\S1S j5       r\S4S j5       rS5S jr\S1S j5       r\S4S j5       rS5S jrS rS6S jrS6S jrS7S jrS7S jr\S8S j5       rSrS\S '   \S8S! j5       r\S9S" j5       r \S# 5       r!\S:S$ j5       r"\S;S% j5       r#\S<S& j5       r$\S9S<S' jj5       r%S(r&g)=TimeZoneInfoi  a#  
Main class for handling Windows time zones.
Usage:
    TimeZoneInfo(<Time Zone Standard Name>, [<Fix Standard Time>])

If <Fix Standard Time> evaluates to True, daylight savings time is
calculated in the same way as standard time.

>>> tzi = TimeZoneInfo('Pacific Standard Time')
>>> march31 = datetime.datetime(2000,3,31)

We know that time zone definitions haven't changed from 2007
to 2012, so regardless of whether dynamic info is available,
there should be consistent results for these years.
>>> subsequent_years = [march31.replace(year=year)
...     for year in range(2007, 2013)]
>>> offsets = set(tzi.utcoffset(year) for year in subsequent_years)
>>> len(offsets)
1

Cannot create a `TimeZoneInfo` with an invalid name.
>>> TimeZoneInfo('Does not exist')
Traceback (most recent call last):
...
ValueError: Timezone Name 'Does not exist' not found
>>> TimeZoneInfo(None)
Traceback (most recent call last):
...
ValueError: subkey name cannot be empty
>>> TimeZoneInfo("")
Traceback (most recent call last):
...
ValueError: subkey name cannot be empty
z7SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zonesc                    [        U[        5      (       a  U R                  U5        OXl        U R	                  5         X l        g r9   )r   rd   _LoadFromTZItimeZoneName_LoadInfoFromKeyfixedStandardTime)r!   paramfix_standard_times      r)   r*   TimeZoneInfo.__init__3  s8    
 e/00e$ %!!#!2r,   c                2    U R                   U R                  4$ r9   )
staticInfor   r   s    r)   __getinitargs__TimeZoneInfo.__getinitargs__@  s    !7!788r,   c                B   [        U R                  S5      5      nUR                  U R                  U R                  5      n[        R                  [        R                  U R                  5      n UR                  U5      nU$ ! [         a    [        SU< S35      ef = f)zAFind the registry key for the time zone name (self.timeZoneName).StdzTimezone Name z
 not found)dict_get_indexed_time_zone_keysgetr   _RegKeyDictopenwinregHKEY_LOCAL_MACHINEtzRegKeysubkeyFileNotFoundErrorrh   )r!   	zoneNamesr   keyr   s        r)   _FindTimeZoneKeyTimeZoneInfo._FindTimeZoneKeyC  s     99%@A	 !}}T%6%68I8IJv88$--H	JZZ-F  ! 	J~l-=ZHII	Js   0B Bc                    U R                  5       nUS   U l        US   U l        US   U l        [	        US   5      U l        U R                  U5        g)zcLoads the information from an opened time zone registry key
into relevant fields of this TZI objectDisplayr   DltTZIN)r   displayNamestandardNamedaylightNamerd   r   _LoadDynamicInfoFromKeyr!   r   s     r)   r   TimeZoneInfo._LoadInfoFromKeyS  sT     ##%y>JJ,SZ8$$S)r,   c                    UR                   U l        SU l        UR                   U l        UR                  U l        Xl        g )NUnknown)rX   r   r   r   r[   r   r   r   s     r)   r   TimeZoneInfo._LoadFromTZI]  s9    --$----r,   c                    UR                  S5      nUS	 US	 UR                  5        VVs/ s H  u  p4[        U5      [	        U5      4PM     nnn[        USS0[        R                  S9U l        g! [         a     gf = fs  snnf )ag  
>>> tzi = TimeZoneInfo('Central Standard Time')

Here's how the RangeMap is supposed to work:
>>> m = RangeMap(zip([2006,2007], 'BC'),
...     sort_params = {"reverse": True},
...     key_match_comparator=operator.ge)
>>> m.get(2000, 'A')
'A'
>>> m[2006]
'B'
>>> m[2007]
'C'
>>> m[2008]
'C'

>>> m[RangeMap.last_item]
'B'

>>> m.get(2008, m[RangeMap.last_item])
'C'


Now test the dynamic info (but fallback to our simple RangeMap
on systems that don't have dynamicInfo).

>>> dinfo = getattr(tzi, 'dynamicInfo', m)
>>> 2007 in dinfo
True
>>> 2008 in dinfo
False
>>> dinfo[2007] == dinfo[2008] == dinfo[2012]
True
zDynamic DSTN
FirstEntry	LastEntryreverseTsort_paramskey_match_comparator)	r   r   itemsrT   rd   RangeMapoperatorgedynamicInfo)r!   r   inforL   valuesinfoss         r)   r   $TimeZoneInfo._LoadDynamicInfoFromKeyd  s    F	::m,D  IM


HTSY*623 	 

 $"D)!)
 ! 		

s   A2 "B2
A?>A?c                    U R                   R                   SU R                  < 3nU R                  (       a  US-  nUS-  nU$ )N(z, True))rk   rD   r   r   )r!   r   s     r)   __repr__TimeZoneInfo.__repr__  sE    NN++,Ad.?.?-BC!!hF#r,   c                    U R                   $ r9   )r   r   s    r)   __str__TimeZoneInfo.__str__  s    r,   c                    g r9   r   r!   dts     r)   tznameTimeZoneInfo.tzname  s    47r,   c                    g r9   r   r   s     r)   r  r    s    (+r,   c                   Uc  gU R                  U5      nU R                  UR                  5      nX#R                  * :X  a  U R                  $ X#R
                  * :X  a  U R                  $ [        SUUUR                  UR
                  5      e)z
>>> MST = TimeZoneInfo('Mountain Standard Time')
>>> MST.tzname(datetime.datetime(2003, 8, 2))
'Mountain Daylight Time'
>>> MST.tzname(datetime.datetime(2003, 11, 25))
'Mountain Standard Time'
>>> MST.tzname(None)

NzUnexpected daylight bias)dst
getWinInforL   r]   r   rZ   r   rh   )r!   r   r  winInfos       r)   r  r    s     :hhrl//"''*(((($$$****$$$&!!!!
 	
r,   c                    [        U S0 5      (       d  U R                  $ U R                  R                  XR                  [        R
                     5      $ )zH
Return the most relevant "info" for this time zone
in the target year.
r   )r3   r   r   r   r   	last_item)r!   
targetYears     r)   r  TimeZoneInfo.getWinInfo  sG    
 t]B//??" ##J0@0@ASAS0TUUr,   c                j    U R                  UR                  5      nUR                  UR                  -   $ r9   )r  rL   rW   rZ   r!   r   r  s      r)   _getStandardBiasTimeZoneInfo._getStandardBias  )    //"''*||g3333r,   c                j    U R                  UR                  5      nUR                  UR                  -   $ r9   )r  rL   rW   r]   r  s      r)   _getDaylightBiasTimeZoneInfo._getDaylightBias  r  r,   c                    g r9   r   r   s     r)   	utcoffsetTimeZoneInfo.utcoffset  s    +.r,   c                    g r9   r   r   s     r)   r  r    s    FIr,   c                ~    Uc  gU R                  UR                  5      nUR                  * U R                  U5      -   $ )z>Calculates the utcoffset according to the datetime.tzinfo specN)r  rL   rW   r  r  s      r)   r  r    s5    ://"''*}txx|++r,   c                    g r9   r   r   s     r)   r  TimeZoneInfo.dst  s    %(r,   c                    g r9   r   r   s     r)   r  r    s    @Cr,   c                    Uc  gU R                  UR                  5      nU R                  (       d%  U R                  U5      (       a  UR                  nU* $ UR
                  nU* $ )zN
Calculate the daylight savings offset according to the
datetime.tzinfo spec.
N)r  rL   r   _inDaylightSavingsr]   rZ   )r!   r   r  r   s       r)   r  r    s_    
 ://"''*%%$*A*A"*E*E**F w **Fwr,   c                   UR                  S S9nU R                  UR                  5      n U R                  UR                  5      nU R	                  UR                  5      nXBR
                  -   nX2R                  -   nX4:  a  Xas=:*  =(       a    U:  Os  nU$ XQs=:  =(       a    U:*  Os  (       + n U$ ! [         a    Sn U$ f = f)NtzinfoF)replacer  rL   GetDSTStartTimeGetDSTEndTimer]   rZ   rh   )r!   r   r  dstStartdstEnd	dstEndAdjdstStartAdjin_dsts           r)   r  TimeZoneInfo._inDaylightSavings  s    ZZtZ$//"''*	++BGG4H''0F
 !6!66I #%:%::K $66Y6  (;;;<   	 F	s   A+B5 B5 5CCc                B    U R                  U5      R                  U5      $ )zCGiven a year, determines the time when daylight savings time starts)r  r   r   s     r)   r"  TimeZoneInfo.GetDSTStartTime      t$::4@@r,   c                B    U R                  U5      R                  U5      $ )z=Given a year, determines the time when daylight savings ends.)r  r   r   s     r)   r#  TimeZoneInfo.GetDSTEndTime  r,  r,   c                4    U R                   UR                   :H  $ r9   __dict__r:   s     r)   r6   TimeZoneInfo.__eq__      }}..r,   c                4    U R                   UR                   :g  $ r9   r0  r:   s     r)   r;   TimeZoneInfo.__ne__  r3  r,   c                L    [         R                  5       u  pU(       + nU " X#5      $ )a  Returns the local time zone as defined by the operating system in the
registry.
>>> localTZ = TimeZoneInfo.local()
>>> now_local = datetime.datetime.now(localTZ)
>>> now_UTC = datetime.datetime.utcnow()  # deprecated
>>> (now_UTC - now_local) < datetime.timedelta(seconds = 5)
Traceback (most recent call last):
...
TypeError: can't subtract offset-naive and offset-aware datetimes

>>> now_UTC = now_UTC.replace(tzinfo = TimeZoneInfo('GMT Standard Time', True))

Now one can compare the results of the two offset aware values
>>> (now_UTC - now_local) < datetime.timedelta(seconds = 5)
True

Or use the newer `datetime.timezone.utc`
>>> now_UTC = datetime.datetime.now(datetime.timezone.utc)
>>> (now_UTC - now_local) < datetime.timedelta(seconds = 5)
True
)rd   r   )r   r   r   r   s       r)   localTimeZoneInfo.local"  s+    . (//1
 !%H 4++r,   NzClassVar[Self | None]_tzutcc                X    U R                   (       d  U " SS5      U l         U R                   $ )zReturns a time-zone representing UTC.

Same as TimeZoneInfo('GMT Standard Time', True) but caches the result
for performance.

>>> isinstance(TimeZoneInfo.utc(), TimeZoneInfo)
True
zGMT Standard TimeT)r9  )r   s    r)   utcTimeZoneInfo.utcF  s$     zz0$7CJzzr,   c                    [         R                  [        R                  [        R
                  5      nU (       a  UR                  U 5      nU$ )z5Return the registry key that stores time zone details)r   r   r   r   r   r   r   )r   r   s     r)   _get_time_zone_keyTimeZoneInfo._get_time_zone_keyU  s8     v88,:O:OP**V$C
r,   c                 F    [         R                  5       R                  5       $ )z:Returns the names of the (registry keys of the) time zones)r   r>  subkeysr   r,   r)   _get_time_zone_key_names%TimeZoneInfo._get_time_zone_key_names]  s     ..088::r,   c                   ^  [        [        R                  5       5      nU 4S jn[        X!5      nS [	        X15       5       $ )z
Get the names of the registry keys indexed by a value in that key,
ignoring any keys for which that value is empty or missing.
c                P   > [         R                  U 5      nUR                  T5      $ r9   )r   r>  r   )ra   r   	index_keys     r)   get_index_valueATimeZoneInfo._get_indexed_time_zone_keys.<locals>.get_index_valuej  s"    11(;C779%%r,   c              3  >   #    U  H  u  pU(       d  M  X4v   M     g 7fr9   r   )r   r}   ra   s      r)   r   ;TimeZoneInfo._get_indexed_time_zone_keys.<locals>.<genexpr>p  s      
5K/%uU5Ks   
)listr   rB  mapzip)rF  	key_namesrG  r   s   `   r)   r   (TimeZoneInfo._get_indexed_time_zone_keysb  s@     >>@A		& _0
585K
 	
r,   c                 l    [         R                  5       n U  Vs/ s H  oR                  PM     sn$ s  snf )zY
Return a list of time zone names that can
be used to initialize TimeZoneInfo instances.
)r   get_sorted_time_zonesr   )tzstzs     r)   get_sorted_time_zone_names'TimeZoneInfo.get_sorted_time_zone_namest  s,     002*-.#B#...s   1c                 h    [         R                  5        V s/ s H  n [        U 5      PM     sn $ s  sn f r9   )r   rB  )r   s    r)   get_all_time_zonesTimeZoneInfo.get_all_time_zones}  s)    )5)N)N)PQ)PAQ)PQQQs   /c                d    U =(       d    S n [         R                  5       nUR                  U S9  U$ )aB  
Return the time zones sorted by some key.
key must be a function that takes a TimeZoneInfo object and returns
a value suitable for sorting on.
The key defaults to the bias (descending), as is done in Windows
(see https://web.archive.org/web/20130723075340/http://blogs.msdn.com/b/michkap/archive/2006/12/22/1350684.aspx)
c                0    U R                   R                  * $ r9   )r   rW   )r   s    r)   <lambda>4TimeZoneInfo.get_sorted_time_zones.<locals>.<lambda>  s    3>>#6#6"6r,   r   )r   rW  sort)r   zoness     r)   rQ  "TimeZoneInfo.get_sorted_time_zones  s0     76//1

s
r,   )r   r   r   r   r   r   r   )F)r   zstr | TimeZoneDefinitionr   rA   r>   r?   )r>   ztuple[TimeZoneDefinition, bool])r>   r   r=   )r   rd   )r>   r^   )r   r   r>   r^   )r   r?   r>   r?   )r   datetime.datetime | Noner>   
str | None)r
  rT   r>   rd   )r   r   r>   r   )r   ra  r>   zdatetime.timedelta | None)rL   rT   r>   r   rB   r   r9   )Indexr@   )r>   zlist[TimeZoneInfo])'rD   rE   rF   rG   r   r   r*   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r"  r#  r6   r;   r   r7  r9  rH   r;  r   r>  rB  r   rT  rW  rQ  rI   r   r,   r)   r   r     s   !H JH
 #(
3'
3  
3 
	
39 *3
j  7 7+ +
>
V44 . .I I, ( (C C:AA// , ,B %)F!(    ; ; 
 
" / / R R  r,   r   c                      \ rS rSrSS jr\ S         SS jj5       rSS jrS rS r	\
S 5       r\
S 5       r\
      SS	 j5       rS
rg)r   i  c                Z    [         R                  U 5        Xl        U R                  5         g r9   )r   r*   r   _RegKeyDict__load_valuesr   s     r)   r*   _RegKeyDict.__init__  s    dr,   c                B    [        [        R                  " XX45      5      $ r9   )r   r   	OpenKeyEx)r   r   sub_keyreservedaccesss        r)   r   _RegKeyDict.open  s     6++C(KLLr,   c                z    U(       d  [        S5      e[        [        R                  " U R                  U5      5      $ )Nzsubkey name cannot be empty)rh   r   r   ri  r   )r!   r%   s     r)   r   _RegKeyDict.subkey  s-    :;;6++DHHd;<<r,   c                    U R                  U R                  5       VVVs/ s H	  u  po1U4PM     nnnnU R                  U5        g s  snnnf r9   )_enumerate_reg_valuesr   update)r!   r   vr   pairss        r)   __load_values_RegKeyDict.__load_values  s?    )-)C)CDHH)MN)MIQ1Q)MNE Os   Ac                8    U R                  U R                  5      $ r9   )_enumerate_reg_keysr   r   s    r)   rA  _RegKeyDict.subkeys  s    ''11r,   c                J    [         R                  U [        R                  5      $ r9   )r   _enumerate_regr   	EnumValuer]  s    r)   rq  !_RegKeyDict._enumerate_reg_values  s    ))#v/?/?@@r,   c                J    [         R                  U [        R                  5      $ r9   )r   r{  r   EnumKeyr]  s    r)   rx  _RegKeyDict._enumerate_reg_keys  s    ))#v~~>>r,   c              #  d   #     [        5        H  nU" X5      v   M     g! [         a     gf = f7f)z8Enumerates an open registry key as an iterable generatorN)r   OSError)r   funcindexs      r)   r{  _RegKeyDict._enumerate_reg  s2     
	3&& ! 		s   0  0
-0-0r]  N)r   winreg._KeyType)r   i  )
r   r  rj  r^   rk  rT   rl  rT   r>   r   )r%   r^   r>   r   )r   r   r  zCallable[[_T, int], _VT]r>   zGenerator[_VT, None, None])rD   rE   rF   rG   r*   r   r   r   rf  rA  r   rq  rx  r{  rI   r   r,   r)   r   r     s    
 RXM!M,/M;>MLOM	M M
=
2 A A ? ? /	# r,   r   c                 d    [         R                   R                  [        R                  5       5      $ )z
Return the UTC time now with timezone awareness as enabled
by this module
>>> now = utcnow()

>>> (now - datetime.datetime.now(datetime.timezone.utc)) < datetime.timedelta(seconds = 5)
True
>>> type(now.tzinfo) is TimeZoneInfo
True
)r   nowr   r;  r   r,   r)   utcnowr    s$       !1!1!344r,   c                 d    [         R                   R                  [        R                  5       5      $ )z
Return the local time now with timezone awareness as enabled
by this module
>>> now_local = now()

>>> (now_local - datetime.datetime.now(datetime.timezone.utc)) < datetime.timedelta(seconds = 5)
True
>>> type(now_local.tzinfo) is TimeZoneInfo
True
)r   r  r   r7  r   r,   r)   r  r    s$       !3!3!566r,   c                     [        S5      n [        R                  " SSSU S9R                  5       S:g  nU(       + =(       a(    [        R                  " SSSU S9R                  5       S:H  nA [        5       $ )	z
Run a few known tests to determine the capabilities of
the time zone database on this machine.
Note Dynamic Time Zone support is not available on any
platform at this time; this
is a limitation of this library, not the platform.zMountain Standard Time  rq      r  )	r  rq   r  r   r   r      2  r     )	r  rq   r  r   r   r   r   r  r   )r   r   utctimetuplelocals)r   MissingTZPatchDynamicTZSupports      r)   GetTZCapabilitiesr    sz     /
0C&&tR3?LLN 
S 
N *) :h.?.?b!C/ln9/: 	8Or,   c                  (    \ rS rSrSS jrSS jrSrg)DLLHandleCachei  c                    0 U l         g r9   )_DLLHandleCache__cacher   s    r)   r*   DLLHandleCache.__init__  s	    ')r,   c                    UR                  5       nU R                  R                  U[        R                  " U5      5      $ r9   )lowerr  
setdefaultr   LoadLibrary)r!   filenamer   s      r)   __getitem__DLLHandleCache.__getitem__  s0    nn||&&sH,@,@,EFFr,   )__cacheNr=   )r  r^   r>   rT   )rD   rE   rF   rG   r*   r  rI   r   r,   r)   r  r    s    *Gr,   r  c                *   [         R                  " S5      nUR                  U 5      nU(       d   S5       eUR                  5       n [        US      n[
        R                  " U[        US   5      5      nU$ ! [
        R                   a    Sn U$ f = f)a  Resolve a multilingual user interface resource for the time zone name

spec should be of the format @path,-stringID[;comment]
see https://learn.microsoft.com/en-ca/windows/win32/api/timezoneapi/ns-timezoneapi-time_zone_information
for details

>>> import sys
>>> result = resolveMUITimeZone('@tzres.dll,-110')
>>> expectedResultType = [type(None),str][sys.getwindowsversion() >= (6,)]
>>> type(result) is expectedResultType
True
z5@(?P<dllname>.*),-(?P<index>\d+)(?:;(?P<comment>.*))?zCould not parse MUI specdllnamer  N)	recompilematch	groupdictDLLCacher   
LoadStringrT   error)specpatternmatcherr  handler   s         r)   resolveMUITimeZoner    s     jjQRGmmD!G...7!!#I)I./%00Yw=O9PQ M >> Ms   /A8 8BBc                      \ rS rSrSr0 \R                  4       SS jjr\    SS j5       r	SS jr
\SS j5       r\SSS jj5       rSSS	 jjr      SS
 jrSS jr\" SS0 5      " 5       r " S S\5      r\" S5      r\" S5      rSrg)r   i  at  
A dictionary-like object that uses the keys as bounds for a range.
Inclusion of the value for that range is determined by the
key_match_comparator, which defaults to less-than-or-equal.
A value is returned for a key if it is the first key that matches in
the sorted list of keys.

One may supply keyword parameters to be passed to the sort function used
to sort keys (i.e. key, reverse) as sort_params.

Create a map that maps 1-3 -> 'a', 4-6 -> 'b'

>>> r = RangeMap({3: 'a', 6: 'b'})  # boy, that was easy
>>> r[1], r[2], r[3], r[4], r[5], r[6]
('a', 'a', 'a', 'b', 'b', 'b')

Even float values should work so long as the comparison operator
supports it.

>>> r[4.5]
'b'

Notice that the way rangemap is defined, it must be open-ended
on one side.

>>> r[0]
'a'
>>> r[-1]
'a'

One can close the open-end of the RangeMap by using undefined_value

>>> r = RangeMap({0: RangeMap.undefined_value, 3: 'a', 6: 'b'})
>>> r[0]
Traceback (most recent call last):
...
KeyError: 0

One can get the first or last elements in the range by using RangeMap.Item

>>> last_item = RangeMap.Item(-1)
>>> r[last_item]
'b'

.last_item is a shortcut for Item(-1)

>>> r[RangeMap.last_item]
'b'

Sometimes it's useful to find the bounds for a RangeMap

>>> r.bounds()
(0, 6)

RangeMap supports .get(key, default)

>>> r.get(0, 'not found')
'not found'

>>> r.get(7, 'not found')
'not found'

One often wishes to define the ranges by their left-most values,
which requires use of sort params and a key_match_comparator.

>>> r = RangeMap({1: 'a', 4: 'b'},
...     sort_params=dict(reverse=True),
...     key_match_comparator=operator.ge)
>>> r[1], r[2], r[3], r[4], r[5], r[6]
('a', 'a', 'a', 'b', 'b', 'b')

That wasn't nearly as easy as before, so an alternate constructor
is provided:

>>> r = RangeMap.left({1: 'a', 4: 'b', 7: RangeMap.undefined_value})
>>> r[1], r[2], r[3], r[4], r[5], r[6]
('a', 'a', 'a', 'b', 'b', 'b')

c                F    [         R                  X5        X l        X0l        g r9   )r   r*   r   r  )r!   sourcer   r   s       r)   r*   RangeMap.__init__j  s     	d#&)
r,   c                2    U " USS0[         R                  S9$ )Nr   Tr   )r   r   )r   r  s     r)   leftRangeMap.leftv  s!     D 1
 	
r,   c                "   [        U 40 U R                  D6n[        U[        R                  5      (       a  U R                  X!   5      nU$ U R                  X!5      n[        R                  X5      nU[        R                  L a  [        U5      eU$ r9   )
sortedr   r   r   Itemr  _find_first_match_r   undefined_valueKeyError)r!   itemsorted_keysr   r   s        r)   r  RangeMap.__getitem__  s    T6T%5%56dHMM**%%k&78F 	 ))+<C%%d0F111sm#r,   c                    g r9   r   r!   r   defaults      r)   r   RangeMap.get  s    >Ar,   Nc                    g r9   r   r  s      r)   r   r    s    ILr,   c                0     X   $ ! [          a    Us $ f = f)z
Return the value for key if key is in the dictionary, else default.
If default is not given, it defaults to None, so that this method
never raises a KeyError.
)r  r  s      r)   r   r    s#    	9 	N	s    c                    [         R                  " U R                  U5      n[        X15      n [	        U5      $ ! [
         a    [        U5      S ef = fr9   )	functoolspartialr  filternextStopIterationr  )r!   keysr  is_matchmatchess        r)   r  RangeMap._find_first_match_  sN     $$TZZ6(	+=  	+4.d*	+s	   
9 Ac                z    [        U 40 U R                  D6nU[        R                     U[        R                     4$ r9   )r  r   r   
first_itemr	  )r!   r  s     r)   boundsRangeMap.bounds  s8    T6T%5%56H//0+h>P>P2QRRr,   RangeValueUndefinedr   c                      \ rS rSrSrSrg)RangeMap.Itemi  zRangeMap Itemr   N)rD   rE   rF   rG   r   rI   r   r,   r)   r  r    s    r,   r  r   )r  r   )r  LSupportsKeysAndGetItem[_RangeMapKT, _VT] | Iterable[tuple[_RangeMapKT, _VT]]r   zMapping[str, Any]r   z*Callable[[_RangeMapKT, _RangeMapKT], bool]r>   r?   )r  r  r>   r   )r  r   r>   r   )r   r   r  r   r>   z_VT | _Tr9   )r   r   r  r?   r>   z
_VT | None)r   r   r  z	_T | Noner>   z_VT | _T | None)r  zIterable[_RangeMapKT]r  r   r>   r   )r>   ztuple[_RangeMapKT, _RangeMapKT])rD   rE   rF   rG   r   r   ler*   r   r  r  r   r   r  r  typer  rT   r  r  r	  rI   r   r,   r)   r   r     s    Nj *,KS;;
* Y
*
 '
* I
* 

* 
 Y

 

 
	 A AL L
+)+1<+	+S
 0"b9;Os  aJRIr,   r   r   )r>   zdict[str, bool])r  r^   r>   rb  )5r   
__future__r   r   r  loggingr   r  rs   r   	itertoolsr   typingr   r   r   r   r	   r
   r   r   r   r   r   	_operatorr   	_typeshedr   typing_extensionsr   
__author__r   r   r   	getLogger__file__logr   rK   rV   r`   rd   r   r   r^   r   r  r  r  r  r  r  r   r   r,   r)   <module>r     s'  kZ #     	      -0&2
m+@AT]en!
%& %&P
 
	M 	$9 h6 hVA8?? AH)$sCx. )X574G G 6XtK$% Xr,   