
    (ph                        S r SSKrSSKrSSKrSSKJr  \R                  R                  S\R                  R                  5      r	Sr
Sr\R                  " S\R                  5      rS rSS jr " S	 S
\R                  5      rg)zHelpers 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
c                 8    [         [        R                  " U S9-   $ )zConvert 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)values    I/var/www/html/venv/lib/python3.13/site-packages/proto/datetime_helpers.py_from_microsecondsr   ,   s     **>>>    c                     U(       d-  U R                   b   U R                  SS9U R                  5       -
  n U R                  [        5      $ )ag  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)r	   ignore_zones     r
   _to_rfc3339r   9   s;     5<<3T*U__->>>>/**r   c                   r   ^  \ rS rSrSrSrS rU 4S jr\S 5       r	S r
\S 5       rS	 r\S
 5       rSrU =r$ )DatetimeWithNanosecondsL   zmTrack nanosecond in addition to normal datetime attrs.

Nanosecond can be passed only as a keyword argument.
)_nanosecondc                     UR                  SS5      nUS:  a  SU;   a  [        S5      eUS-  US'   [        R                  R                  " U /UQ70 UD6nU=(       d    SUl        U$ )N
nanosecondr   microsecond1Specify only one of 'microsecond' or 'nanosecond'  )pop	TypeErrorr   __new__r   )clsargskwnanosinsts        r
   r!   DatetimeWithNanoseconds.__new__U   sl    |Q'19" STT %B}  ((:t:r: :Ar   c                 ,  > SU;   nSU;   nUR                  SS5      nU R                  nU(       a  U(       a  [        S5      eU(       a  US-  US'   [        TU ]  " U0 UD6nU(       a  UR
                  S-  Ul        U$ U(       a  XWl        U$ Xgl        U$ )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.
r   r   r   r   r   )r   r   r    superr   r   r   )	selfr#   r$   ms_providedns_providedprovided_ns
prev_nanosr&   	__class__s	           r
   r   DatetimeWithNanoseconds.replace`   s     $r)"b(ff\1-__
;OPP +t 3B}w++#//$6D  *
   *r   c                 F    U R                   =(       d    U R                  S-  $ )z Read-only: nanosecond precision.r   )r   r   )r*   s    r
   r   "DatetimeWithNanoseconds.nanosecond   s      :4#3#3d#::r   c                     U R                   S:X  a  [        U 5      $ [        U R                   5      R                  SS5      R	                  S5      nSR                  U R                  [        5      U5      $ )zhReturn an RFC3339-compliant timestamp.

Returns:
    (str): Timestamp string according to RFC3339 spec.
r   	   0z{}.{}Z)r   r   strrjustrstripformatr   _RFC3339_NO_FRACTION)r*   r%   s     r
   rfc3339DatetimeWithNanoseconds.rfc3339   s`     q t$$D$$%++As3::3?t}}-ABEJJr   c                    [         R                  U5      nUc)  [        SR                  U[         R                  5      5      e[
        R
                  R                  UR                  S5      [        5      nUR                  S5      nUc  SnOS[        U5      -
  n[        U5      SU-  -  nU " UR                  UR                  UR                  UR                  UR                  UR                   U[
        R"                  R$                  S9$ )a+  Parse 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
z)Timestamp: {}, does not match pattern: {}no_fractionr%   r   r4   
   r   r   )_RFC3339_NANOSmatch
ValueErrorr9   patternr   strptimegroupr:   lenintyearmonthdayhourminutesecondtimezoneutc)r"   stamp
with_nanosbarefractionr%   scales          r
   from_rfc3339$DatetimeWithNanoseconds.from_rfc3339   s     $))%0
;BB>11 
   ))]+-A
 ##G,EH%EMRY/EIIJJHHIIKKKK$$((	
 		
r   c                    U R                   b  U O&U R                  [        R                  R                  S9nU[
        -
  n[        UR                  5       5      nU R                  =(       d    U R                  S-  n[        R                  " X4S9$ )zqReturn a timestamp message.

Returns:
    (:class:`~google.protobuf.timestamp_pb2.Timestamp`): Timestamp message
r   r   )secondsr%   )r   r   r   rO   rP   r   rH   total_secondsr   r   r   	Timestamp)r*   r&   deltarY   r%   s        r
   timestamp_pb$DatetimeWithNanoseconds.timestamp_pb   s}     {{& X%6%6%:%:; 	
 z!e))+,  ;D$4$4t$;&&wDDr   c                    [        UR                  S-  5      n[        U5      nU " UR                  UR                  UR
                  UR                  UR                  UR                  UR                  [        R                  R                  S9$ )zParse 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@   )rH   rY   r   rI   rJ   rK   rL   rM   rN   r%   r   rO   rP   )r"   rQ   r   rS   s       r
   from_timestamp_pb)DatetimeWithNanoseconds.from_timestamp_pb   sn     5==3./!,/IIJJHHIIKKKK{{$$((	
 		
r    )__name__
__module____qualname____firstlineno____doc__	__slots__r!   r   propertyr   r;   classmethodrV   r]   r`   __static_attributes____classcell__)r/   s   @r
   r   r   L   sc    
 !I D ; ;	K &
 &
PE  
 
r   r   )T)rg   calendarr   regoogle.protobufr   fromtimestamprO   rP   r   r   r:   compileVERBOSErA   r   r   r   rb   r   r
   <module>rs      s    #   	 ) ,,Q0A0A0E0EF
)* 	 JJ
?+&U
h// U
r   