o
    f                     @   s:   d dl Z d dlmZ dd Zdd Zdd Zdd	d
ZdS )    N)get_tz_backendc                 C   s   | d  tdddS )zNormalize timezone names by replacing special characters with space.

    For proper sorting, using spaces makes comparisons more consistent.

    :param str tztuple: tuple of timezone and representation
        )-_)	translatestr	maketrans)tztuple r   I/var/www/html/venv/lib/python3.10/site-packages/timezone_field/choices.pynormalize_standard   s   r   c                 C   s,   | d   d }|dddd}t|S )zNormalize timezone GMT names for sorting.

    For proper sorting, using GMT values as a positive or negative number.

    :param str tztuple: tuple of timezone and representation
    r   r   GMT :)splitreplaceint)r
   gmtcmpr   r   r   normalize_gmt   s   r   c                 C   s8   g }| D ]}t |}|||ddf qt|tdS )z
    Given a list of timezones (either strings of timezone objects),
    return a list of choices with
        * values equal to what was passed in
        * display strings as the timezone name without underscores
    r   r   key)r   appendr   sortedr   )	timezoneschoicestztz_strr   r   r   standard   s
   r   c                 C   s   t |}|ptj|j}g }| D ]>}t|}|||}|j|jd| }dj|t	|kr2dndtt	|
ddd |dd	d
}	||||	f q|jdd d dd |D }
t|
tdS )aC  
    Given a list of timezones (either strings of timezone objects),
    return a list of choices with
        * values equal to what was passed in
        * display strings formated with GMT offsets and without
          underscores. For example: "GMT-05:00 America/New York"
        * sorted by their timezone offset
    )tzinfozGMT{sign}{gmt_diff} {timezone}+r      Nr   r   )signgmt_difftimezonec                 S   s   | d S )Nr   r   )xr   r   r   <lambda>@   s    z!with_gmt_offset.<locals>.<lambda>r   c                 S   s   g | ]	\}}}||fqS r   r   ).0zeroonetwor   r   r   
<listcomp>A   s    z#with_gmt_offset.<locals>.<listcomp>)r   datetimenow	utc_tzobjr   
astimezoneto_tzobjr   formatabszfillr   sortr   r   )r   r/   use_pytz
tz_backend_choicesr   r   now_tzdeltadisplayr   r   r   r   with_gmt_offset*   s    	
r=   )NN)r.   timezone_field.backendsr   r   r   r   r=   r   r   r   r   <module>   s    
