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re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 )"zGenerate 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  | qt|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:   


]
