HEX
Server: LiteSpeed
System: Linux server.nevid-deploma.com 4.18.0-553.111.1.lve.el8.x86_64 #1 SMP Fri Mar 13 13:42:17 UTC 2026 x86_64
User: smilepac (1037)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/cppython/lib/python3.8/site-packages/proto/__pycache__/datetime_helpers.cpython-38.pyc
U

JD�g��@sxdZddlZddlZddlZddlmZej�dejj�Z	dZ
dZe�dej
�Zdd�Zdd
d�ZGdd
�d
ej�ZdS)zHelpers for :mod:`datetime`.�N)�
timestamp_pb2z%Y-%m-%dT%H:%M:%S.%fZz%Y-%m-%dT%H:%M:%Sah
    (?P<no_fraction>
        \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}  # YYYY-MM-DDTHH:MM:SS
    )
    (                                        # Optional decimal part
     \.                                      # decimal point
     (?P<nanos>\d{1,9})                      # nanoseconds, maybe truncated
    )?
    Z                                        # Zulu
cCsttj|d�S)aConvert timestamp in microseconds since the unix epoch to datetime.

    Args:
        value (float): The timestamp to convert, in microseconds.

    Returns:
        datetime.datetime: The datetime object equivalent to the timestamp in
            UTC.
    )�microseconds)�
_UTC_EPOCH�datetime�	timedelta)�value�r�C/opt/cppython/lib/python3.8/site-packages/proto/datetime_helpers.py�_from_microseconds,s
r
TcCs,|s"|jdk	r"|jdd�|��}|�t�S)a�Convert a datetime to an RFC3339 timestamp string.

    Args:
        value (datetime.datetime):
            The datetime object to be converted to a string.
        ignore_zone (bool): If True, then the timezone (if any) of the
            datetime object is ignored and the datetime is treated as UTC.

    Returns:
        str: The RFC3339 formatted string representing the datetime.
    N��tzinfo)r�replace�	utcoffset�strftime�_RFC3339_MICROS)rZignore_zonerrr	�_to_rfc33399srcs`eZdZdZdZdd�Z�fdd�Zedd��Zd	d
�Z	e
dd��Zd
d�Ze
dd��Z
�ZS)�DatetimeWithNanosecondszuTrack nanosecond in addition to normal datetime attrs.

    Nanosecond can be passed only as a keyword argument.
    )�_nanosecondcOsR|�dd�}|dkr0d|kr$td��|d|d<tjj|f|�|�}|pJd|_|S)N�
nanosecondr�microsecond�1Specify only one of 'microsecond' or 'nanosecond'��)�pop�	TypeErrorr�__new__r)�cls�args�kw�nanos�instrrr	rUs
zDatetimeWithNanoseconds.__new__csxd|k}d|k}|�dd�}|j}|r2|r2td��|rB|d|d<t�j||�}|rb|jd|_n|rn||_n||_|S)a@Return a date with the same value, except for those parameters given
        new values by whichever keyword arguments are specified. For example,
        if d == date(2002, 12, 31), then
        d.replace(day=26) == date(2002, 12, 26).
        NOTE: nanosecond and microsecond are mutually exclusive arguments.
        rrrrr)rrr�superr
rr)�selfrrZms_providedZns_providedZprovided_nsZ
prev_nanosr��	__class__rr	r
`szDatetimeWithNanoseconds.replacecCs|jp|jdS)z Read-only: nanosecond precision.r)rr)r!rrr	r�sz"DatetimeWithNanoseconds.nanosecondcCs<|jdkrt|�St|j��dd��d�}d�|�t�|�S)z�Return an RFC3339-compliant timestamp.

        Returns:
            (str): Timestamp string according to RFC3339 spec.
        r�	�0z{}.{}Z)rr�str�rjust�rstrip�formatr�_RFC3339_NO_FRACTION)r!rrrr	�rfc3339�s
zDatetimeWithNanoseconds.rfc3339c
Cs�t�|�}|dkr$td�|tj���tj�|�d�t�}|�d�}|dkrPd}ndt	|�}t
|�d|}||j|j|j
|j|j|j|tjjd�S)	akParse RFC3339-compliant timestamp, preserving nanoseconds.

        Args:
            stamp (str): RFC3339 stamp, with up to nanosecond precision

        Returns:
            :class:`DatetimeWithNanoseconds`:
                an instance matching the timestamp string

        Raises:
            ValueError: if `stamp` does not match the expected format
        Nz)Timestamp: {}, does not match pattern: {}Zno_fractionrrr$�
�rr)�_RFC3339_NANOS�match�
ValueErrorr)�patternr�strptime�groupr*�len�int�year�month�day�hour�minute�second�timezone�utc)r�stampZ
with_nanos�bareZfractionr�scalerrr	�from_rfc3339�s6
���
�z$DatetimeWithNanoseconds.from_rfc3339cCsP|jdk	r|n|jtjjd�}|t}t|���}|jp@|j	d}t
j||d�S)z�Return a timestamp message.

        Returns:
            (:class:`~google.protobuf.timestamp_pb2.Timestamp`): Timestamp message
        Nrr)�secondsr)rr
rr<r=rr5�
total_secondsrrr�	Timestamp)r!r�deltarBrrrr	�timestamp_pb�s��z$DatetimeWithNanoseconds.timestamp_pbc
Cs@t|jd�}t|�}||j|j|j|j|j|j|j	t
jjd�S)a&Parse RFC3339-compliant timestamp, preserving nanoseconds.

        Args:
            stamp (:class:`~google.protobuf.timestamp_pb2.Timestamp`): timestamp message

        Returns:
            :class:`DatetimeWithNanoseconds`:
                an instance matching the timestamp message
        g��.Ar-)
r5rBr
r6r7r8r9r:r;rrr<r=)rr>rr?rrr	�from_timestamp_pb�s�z)DatetimeWithNanoseconds.from_timestamp_pb)�__name__�
__module__�__qualname__�__doc__�	__slots__rr
�propertyrr+�classmethodrArFrG�
__classcell__rrr"r	rLs"

(r)T)rK�calendarr�reZgoogle.protobufr�
fromtimestampr<r=rrr*�compile�VERBOSEr.r
rrrrrr	�<module>s
�