
    jg                     2    d dl Z d dlmZ d Zd Zd ZddZy)    N)get_tz_backendc                 V    | d   j                  t        j                  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)tztuples    Q/var/www/html/Stanley/venv/lib/python3.12/site-packages/timezone_field/choices.pynormalize_standardr      s'     1:Cc.B CDD    c                     | d   j                         d   }|j                  dd      j                  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cmps      r   normalize_gmtr      sA     !*


Q
C
++eR
 
(
(b
1Cs8Or   c                     g }| D ]0  }t        |      }|j                  ||j                  dd      f       2 t        |t              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_strs       r   standardr#      sH     GRFNN3456  '122r   c           	      x   t        |      }|xs) t        j                  j                  |j                        }g }| D ]  }t	        |      }|j                  |j                  |            }|j                  |j                        |z
  }dj                  |t        |      k(  rdndt	        t        |            j                  d      dd |j                  dd	      
      }	|j                  |||	f        |j                  d        |D 
cg c]
  \  }
}}||f }}}
}t        |t              S c c}}}
w )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                     | d   S )Nr    )xs    r   <lambda>z!with_gmt_offset.<locals>.<lambda>@   s    !r   r   )r   datetimenow	utc_tzobjr
   
astimezoneto_tzobjr   formatabszfillr   sortr   r   )r   r1   use_pytz
tz_backend_choicesr!   r"   now_tzdeltadisplayzeroonetwor    s                 r   with_gmt_offsetrB   *   s      )J

<""&&z';';<CHR
 3 3F ;<j&:&:;cA299U+U_**1-cr2^^C- : 

 	G,-  MMnM%089ndCSzG9'}-- :s   D5)NN)r0   timezone_field.backendsr   r   r   r#   rB   r-   r   r   <module>rD      s      2E	3.r   