U
    Dvf                     @   s   d Z ddlZddlZddlmZmZ ddlZedZddddd	d
dgZdddddddddddddgZ	d#ddZ
dd Zdd Zdd Zd d! Zed"krddlZddlZee j dS )$zKfontTools.misc.timeTools.py -- tools for working with OpenType timestamps.
    N)datetimetimezone)	ip     r   r   r   r   r   r   r   MonTueWedThuFriSatSunJanFebMarAprMayJunJulAugSepOctNovDecc                 C   s:   | dkrt  } dt| j t| j | jt d| f }|S )a  
    Convert a tuple or struct_time representing a time as returned by gmtime()
    or localtime() to a 24-character string of the following form:

    >>> asctime(time.gmtime(0))
    'Thu Jan  1 00:00:00 1970'

    If t is not provided, the current time as returned by localtime() is used.
    Locale information is not used by asctime().

    This is meant to normalise the output of the built-in time.asctime() across
    different platforms and Python versions.
    In Python 3.x, the day of the month is right-justified, whereas on Windows
    Python 2.7 it is padded with zeros.

    See https://github.com/fonttools/fonttools/issues/455
    Nz%s %s %2s %sz%H:%M:%S %Y)time	localtimeDAYNAMEStm_wday
MONTHNAMEStm_montm_mdaystrftime)ts r"   </tmp/pip-unpacked-wheel-qlge9rch/fontTools/misc/timeTools.pyasctime   s    
r$   c                 C   s   t ttd| t S )Nr   )r$   r   gmtimemax
epoch_diffvaluer"   r"   r#   timestampToString;   s    r*   c                 C   st   | d d   \}}t| dd  d}|jt|tjd}t|}|	 |ksdt
d|  d t| t S )N   z %d %H:%M:%S %Y)monthtzinfo"z" has inconsistent weekday)splitr   strptimereplacer   indexr   utcr   weekdayAssertionErrorint	timestampr'   )r)   ZwkdayZmnthr    Z	wkday_idxr"   r"   r#   timestampFromString?   s    
r8   c                  C   s0   t jd} | d k	r t| t S tt t S )NSOURCE_DATE_EPOCH)osenvirongetr6   r'   r   )Zsource_date_epochr"   r"   r#   timestampNowH   s    r=   c                 C   s   t | t S )N)r6   r'   r(   r"   r"   r#   timestampSinceEpochP   s    r>   __main__)N)__doc__r:   r   r   r   calendartimegmr'   r   r   r$   r*   r8   r=   r>   __name__sysdoctestexittestmodfailedr"   r"   r"   r#   <module>   s:   

	