o
    l^Uf                     @   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g dZg dZ	dddZ
d	d
 Zdd Zdd Zdd ZedkrNddlZddlZee j dS dS )zKfontTools.misc.timeTools.py -- tools for working with OpenType timestamps.
    N)datetimetimezone)	ip     r   r   r   r   r   r   r   )ZMonZTueZWedZThuZFriZSatZSun)NZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecc                 C   s:   | du 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   8lib/python3.10/site-packages/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s2J d|  d t
| t S )N   z %d %H:%M:%S %Y)ZmonthZtzinfo"z" has inconsistent weekday)splitr   strptimereplacer	   indexr   Zutcr   ZweekdayintZ	timestampr   )r   ZwkdayZmnthr   Z	wkday_idxr   r   r   timestampFromString?   s   
r   c                  C   s0   t jd} | d urt| t S tt t S )NSOURCE_DATE_EPOCH)osenvirongetr   r   r   )Zsource_date_epochr   r   r   timestampNowH   s   r$   c                 C   s   t | t S N)r   r   r   r   r   r   timestampSinceEpochP   s   r&   __main__r%   )__doc__r!   r   r   r   ZcalendarZtimegmr   r   r	   r   r   r   r$   r&   __name__sysZdoctestexitZtestmodZfailedr   r   r   r   <module>   s$    

	