o
    .j2                     @  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mZ ddlmZmZ ddlmZmZ er>dd	lmZ ed
ddZedddZeddZg ZeZeekrgee eedd7 ZeeksW[dddZdgZedkrddlmZ ddlmZ ddlm Z  eee egd dS 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/79171631/how-do-i-determine-whether-a-zoneinfo-is-an-alias/79171734#79171734

Run this module:

    python -m icalendar.timezone.equivalent_timezone_ids

    )annotations)defaultdict)datetime	timedeltatzinfo)Path)TYPE_CHECKING
NamedTuple)ZoneInfoavailable_timezones)AmbiguousTimeErrorNonExistentTimeError)Callablei     i     hours   create_timezoneslist[Callable[[str], tzinfo]]namestrc                   s   t  d d G dd dt  fdd| D }tddttd	fd!fdd|tddd}ttjd| d }|	d$}|
dttj d |
d |
d |
d  W d	   |S 1 snw   Y  |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.
    	localtime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    _/home/thesage/.local/lib/python3.10/site-packages/icalendar/timezone/equivalent_timezone_ids.pyTZ;   s   
 r"   c                   s$   g | ]}D ]	} |||qqS r    r    ).0create_timezonetzid)r"   unsorted_tzidsr    r!   
<listcomp>?   s    zmain.<locals>.<listcomp>r   r   Ntzslist[TZ]stepr   startr   endtodoset[str] | Nonereturn5tuple[datetime, dict[timedelta, set[str]]] | set[str]c              	     sB  |du rdd | D }t | dkrtdt | dkr)|| d j | d jhS  |k rtt}zt fdd| D  }W n ttfyL   d	}Y nw |rT t	7  q)| D ]}||j
  | qVt |dkro |7  q)i }| D ]\}	}
|
| | ||d
||	< qu |fS t }| D ]}||j ||j q|S )zGenerate a lookup tree.Nc                 S  s   g | ]}|j qS r    )r   r#   r   r    r    r!   r'   N   s    z/main.<locals>.generate_tree.<locals>.<listcomp>r   ztzs cannot be emptyr   c                 3  sH    | ]}|j  |j  t   ko|j  t kn  V  qd S )N)r   	utcoffsetDISTANCE_FROM_TIMEZONE_CHANGEr1   r+   r    r!   	<genexpr>Y   s    

z.main.<locals>.generate_tree.<locals>.<genexpr>T)r(   r*   r+   r,   r-   )len
ValueErrorremover   r   listallr   r   r3   r   r2   appenditemssetadd)r(   r*   r+   r,   r-   offsetsaround_tz_changer   lookupoffsettz2result)generate_treer4   r!   rE   E   sF   zmain.<locals>.generate_tree!   )r*   equivalent_timezone_ids_z.pywz+'''This file is automatically generated by z'''
zimport datetime

z

lookup = z

__all__ = ['lookup']
)r(   r)   r*   r   r+   r   r,   r   r-   r.   r/   r0   )r   r8   r	   r   STARTENDr   __file__parentopenwriter   )r   r   r(   rA   filefr    )r"   rE   r&   r!   main.   s2   	

0


rQ   __main__)r
   )gettz)timezonerD   N)r   r   r   r   )!__doc__
__future__r   collectionsr   r   r   r   pathlibr   typingr   r	   zoneinfor
   r   pytzr   r   collections.abcr   rI   rJ   r3   DTSdtr;   rQ   __all__r   dateutil.tzrS   rT   r    r    r    r!   <module>   s>    


U