U
    ¤�©j9  ã                   @  s"  d Z ddlmZ ddlmZ ddlmZmZmZ ddlm	Z	 ddl
m
Z
 ddlmZmZmZ ddlmZmZ dd	lmZmZ ed
ddƒZedddƒZedd�Zg ZeZeekrÈe e¡ eedd�7 Zq¦[dddœdd„ZdgZedk�rddlmZ ddlm Z  ddlmZ eee egdƒ dS )aÚ  This module helps identifying the timezone ids and where they differ.

The algorithm: We use the tzname and the utcoffset for each hour from
1970 - 2030.
We make a big map.
If they are equivalent, they are equivalent within the time that is mostly used.

You can regenerate the information from this module.

See also:
- https://stackoverflow.com/questions/79185519/which-timezones-are-equivalent

Run this module:

    python -m icalendar.timezone.equivalent_timezone_ids

é    )Úannotations)Údefaultdict)ÚdatetimeÚ	timedeltaÚtzinfo)ÚPath)Úpprint)ÚCallableÚ
NamedTupleÚOptional)ÚAmbiguousTimeErrorÚNonExistentTimeError)ÚZoneInfoÚavailable_timezonesi²  é   iä  é   ©Úhoursé   zlist[Callable[[str], tzinfo]]Ústr)Úcreate_timezonesÚnamec              	     s  t | |ƒ tƒ ‰ˆ d¡ ˆ d¡ G dd„ dtƒ‰ ‡ ‡fdd„| D ƒ}tdd�ttd	fd
ddddddœ‡ ‡fdd„‰ˆ|tdd�d�}ttƒj	d|› d� }t d|› d�ƒ t ddd� t
|ƒ | d¡�H}| dttƒj› d�¡ | d¡ | d¡ t
||d � | d!¡ W 5 Q R X |S )"zÃGenerate a lookup table for timezone information if unknown timezones.

    We cannot create one lookup for all because they seem to be all equivalent
    if we mix timezone implementations.
    Ú	localtimeZFactoryc                   @  s   e Zd ZU ded< ded< dS )zmain.<locals>.TZr   Útzr   ÚidN)Ú__name__Ú
__module__Ú__qualname__Ú__annotations__© r   r   úN/tmp/pip-unpacked-wheel-g40nyxg1/icalendar/timezone/equivalent_timezone_ids.pyÚTZ:   s   
r!   c                   s$   g | ]}ˆD ]}ˆ ||ƒ|ƒ‘qqS r   r   )Ú.0Zcreate_timezoneZtzid)r!   Úunsorted_tzidsr   r    Ú
<listcomp>>   s    þzmain.<locals>.<listcomp>r   r   Nzlist[TZ]r   r   zOptional[set[str]]z5tuple[datetime, dict[timedelta, set[str]]] | set[str])ÚtzsÚstepÚstartÚendÚtodoÚreturnc              	     s~  |dkrdd„ | D ƒ}t t|ƒ› d�ƒ t t| ƒƒ t| ƒdkrHtdƒ‚t| ƒdkrp| | d j¡ | d jhS ˆ |k �r<ttƒ}zt‡ fdd	„| D ƒƒ }W n tt	fk
rº   d
}Y nX |rÊˆ t
7 ‰ qp| D ]}||j ˆ ¡  |¡ qÎt|ƒdk�rˆ |7 ‰ qpi }| ¡ D ]$\}	} ˆ| |ˆ | ||d�||	< �qˆ |fS t dt| ƒ› d�ƒ tƒ }
| D ]}|
 |j¡ | |j¡ �qZ|
S )zGenerate a lookup tree.Nc                 S  s   g | ]
}|j ‘qS r   )r   ©r"   r   r   r   r    r$   M   s     z/main.<locals>.generate_tree.<locals>.<listcomp>z left to computer   ztzs cannot be emptyr   c                 3  sF   | ]>}|j  ˆ ¡|j  ˆ t ¡  ko8|j  ˆ t ¡kn  V  qd S )N)r   Ú	utcoffsetÚDISTANCE_FROM_TIMEZONE_CHANGEr+   ©r'   r   r    Ú	<genexpr>Z   s   ý
ÿþz.main.<locals>.generate_tree.<locals>.<genexpr>T)r%   r&   r'   r(   r)   zreached end with z* timezones - assuming they are equivalent.)ÚprintÚlenÚ
ValueErrorÚremover   r   ÚlistÚallr   r   r-   r   r,   ÚappendÚitemsÚsetÚadd)r%   r&   r'   r(   r)   ÚoffsetsZaround_tz_changer   ÚlookupÚoffsetÚresult)r!   Úgenerate_treer.   r    r>   D   sR    
ü
    ÿzmain.<locals>.generate_treeé!   )r&   Zequivalent_timezone_ids_z.pyzThe result is written to Ú.z	lookup = Ú )r(   Úwz+'''This file is automatically generated by z'''
zimport datetime

z

lookup = )Ústreamz

__all__ = ['lookup']
)r0   r   r3   r
   r   ÚSTARTÚENDr   Ú__file__Úparentr   ÚopenÚwriter   )r   r   r%   r;   ÚfileÚfr   )r!   r>   r#   r    Úmain,   s6    	


þû 3ÿ

rL   Ú__main__)Úgettz)Útimezone)r   r=   N)!Ú__doc__Ú
__future__r   Úcollectionsr   r   r   r   Úpathlibr   r   Útypingr	   r
   r   Zpytzr   r   Zzoneinfor   r   rD   rE   r-   ZDTSÚdtr6   rL   Ú__all__r   Zdateutil.tzrN   rO   r   r   r   r    Ú<module>   s:   

ÿ
]
þ