U
    ;g                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlZzd dlZW n  ek
r\   d dlmZ Y nX d dl	m
Z
 edZdd Zddd	Zdd
dZdddZdS )    N)zoneinfo)
windows_tztzlocalc                 C   s   t tj|   S )zCGet timezone's offset using built-in function datetime.utcoffset().)intdatetimenow	utcoffsettotal_seconds)tz r   1/tmp/pip-unpacked-wheel-07a7n_dx/tzlocal/utils.pyget_tz_offset   s    r   Tc                 C   s`   t | }tt tt  }t|| dkr\d| d| d}|rRt|t	| dS )aJ  Assert that system's timezone offset equals to the timezone offset found.

    If they don't match, we probably have a misconfiguration, for example, an
    incorrect timezone set in /etc/timezone file in systemd distributions.

    If error is True, this method will raise a ValueError, otherwise it will
    emit a warning.
    <   z.Timezone offset does not match system offset: z != z". Please, check your config files.N)
r   calendartimegmtime	localtimegmtimeabs
ValueErrorwarningswarn)r
   errorZ	tz_offsetZsystem_offsetmsgr   r   r   assert_tz_offset   s    
r   c                 C   s   | d krt jd} | sd S td|   | d dkrD| dd  } | tjkrR| S t j| rt j	| rt j
| t j}d|dd  }|tjkr|S |d tjkr|d S td	 d S )
NTZzFound a TZ environment: r   :   /z$TZ does not contain a time zone name)osenvirongetlogdebugr   Ztz_winpathisabsexistsrealpathsplitsepjoin)tzenvpartsZpossible_tzr   r   r   _tz_name_from_env.   s$    


r/   c              
   C   s   | d krt jd} | sd S | d dkr4| dd  } t j| rt j| rt| }|sh| t jd }t	| d}t
jj||dW  5 Q R  S Q R X zt
| }|W S  t
jk
r   t
d|  d	d Y nX d S )
Nr   r   r   r   r    rb)keyz7tzlocal() does not support non-zoneinfo timezones like z6. 
Please use a timezone in the form of Continent/City)r!   r"   r#   r&   r'   r(   r/   r*   r+   openr   ZZoneInfo	from_fileZZoneInfoNotFoundError)r-   tznameZtzfiler
   r   r   r   _tz_from_envQ   s*    "

r5   )T)N)N)r   r   loggingr!   r   r   r   ImportErrorZ	backportsr   r   	getLoggerr$   r   r   r/   r5   r   r   r   r   <module>   s   


#