U
    ”Ê¹jÒ
  ã                   @   s(   d Z ddlmZmZ eedœdd„ZdS )z:Contains utilities to handle datetimes in Huggingface Hub.é    )ÚdatetimeÚtimezone)Údate_stringÚreturnc              
   C   s¦   zl|   d¡rVd| kr&| dd… d } n0| dd…  d¡\}}|› d|dd… d›d�} t | d¡jtjd	�W S  tk
r  } ztd
| › d�ƒ|‚W 5 d}~X Y nX dS )a¹  
    Parses a date_string returned from the server to a datetime object.

    This parser is a weak-parser is the sense that it handles only a single format of
    date_string. It is expected that the server format will never change. The
    implementation depends only on the standard lib to avoid an external dependency
    (python-dateutil). See full discussion about this decision on PR:
    https://github.com/huggingface/huggingface_hub/pull/999.

    Example:
        ```py
        > parse_datetime('2022-08-19T07:19:38.123Z')
        datetime.datetime(2022, 8, 19, 7, 19, 38, 123000, tzinfo=timezone.utc)
        ```

    Args:
        date_string (`str`):
            A string representing a datetime returned by the Hub server.
            String is expected to follow '%Y-%m-%dT%H:%M:%S.%fZ' pattern.

    Returns:
        A python datetime object.

    Raises:
        :class:`ValueError`:
            If `date_string` cannot be parsed.
    ÚZÚ.Néÿÿÿÿz.000000Zé   z0<6z%Y-%m-%dT%H:%M:%S.%fZ)ÚtzinfozCannot parse 'zS' as a datetime. Date string is expected to follow '%Y-%m-%dT%H:%M:%S.%fZ' pattern.)ÚendswithÚsplitr   ÚstrptimeÚreplacer   ÚutcÚ
ValueError)r   ÚbaseZfractionÚe© r   ú^/var/www/html/bwave/python/venv/lib/python3.8/site-packages/huggingface_hub/utils/_datetime.pyÚparse_datetime   s    

ÿýr   N)Ú__doc__r   r   Ústrr   r   r   r   r   Ú<module>   s   