U
    d/e                     @   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-qhnh9gln/tzlocal/utils.pyget_tz_offset   s    r   Tc                 C   sZ   t | }tt tt  }t|| dkrVd||}|rLt|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.
    <   zXTimezone offset does not match system offset: {} != {}. Please, check your config files.N)r   calendartimegmtime	localtimegmtimeabsformat
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$    


r0   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 Y nX d S )	Nr   r   r   r   r!   rb)keyzotzlocal() does not support non-zoneinfo timezones like %s. 
Please use a timezone in the form of Continent/City)r"   r#   r$   r'   r(   r)   r0   r+   r,   openr   ZZoneInfo	from_fileZZoneInfoNotFoundError)r.   tznameZtzfiler
   r   r   r   _tz_from_envQ   s.    "
r6   )T)N)N)loggingr"   r   r   r   r   r   ImportErrorZ	backportsr   r   	getLoggerr%   r   r   r0   r6   r   r   r   r   <module>   s   


#