
    rh                        d Z ddlZddlZddlZddlmZ ej                  j                  dej                  j                        Z	dZ
dZ ej                  dej                        Zd ZddZ G d	 d
ej                        Zy)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                 <    t         t        j                  |       z   S )a  Convert 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/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/proto/datetime_helpers.py_from_microsecondsr   ,   s     **>>>    c                     |s/| j                   #| j                  d      | j                         z
  } | j                  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)r	   ignore_zones     r
   _to_rfc3339r   9   s;     5<<3T*U__->>>>/**r   c                   h     e Zd ZdZdZd Z fdZed        Zd Z	e
d        Zd Ze
d	        Z xZS )
DatetimeWithNanosecondszuTrack nanosecond in addition to normal datetime attrs.

    Nanosecond can be passed only as a keyword argument.
    )_nanosecondc                     |j                  dd      }|dkD  rd|v rt        d      |dz  |d<   t        j                  j                  | g|i |}|xs d|_        |S )N
nanosecondr   microsecond1Specify only one of 'microsecond' or 'nanosecond'  )pop	TypeErrorr   __new__r   )clsargskwnanosinsts        r
   r    zDatetimeWithNanoseconds.__new__U   sl    |Q'19" STT %B}  ((:t:r: :Ar   c                     d|v }d|v }|j                  dd      }| j                  }|r|rt        d      |r|dz  |d<   t        |   |i |}|r|j
                  dz  |_        |S |r	||_        |S ||_        |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.
        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   zDatetimeWithNanoseconds.replace`   s     $r)"b(ff\1-__
;OPP +t 3B}w++#//$6D  *D
   *Dr   c                 <    | j                   xs | j                  dz  S )z Read-only: nanosecond precision.r   )r   r   )r(   s    r
   r   z"DatetimeWithNanoseconds.nanosecond   s      :4#3#3d#::r   c                     | j                   dk(  rt        |       S t        | j                         j                  dd      j	                  d      }dj                  | j                  t              |      S )zReturn 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
   rfc3339zDatetimeWithNanoseconds.rfc3339   s`     q t$$D$$%++As3::3?t}}-ABEJJr   c           
         t         j                  |      }|)t        dj                  |t         j                              t
        j
                  j                  |j                  d      t              }|j                  d      }|d}ndt        |      z
  }t        |      d|z  z  } | |j                  |j                  |j                  |j                  |j                  |j                   |t
        j"                  j$                        S )ak  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   r0   
   r   r   )_RFC3339_NANOSmatch
ValueErrorr5   patternr   strptimegroupr6   lenintyearmonthdayhourminutesecondtimezoneutc)r!   stamp
with_nanosbarefractionr$   scales          r
   from_rfc3339z$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                    | j                   | n)| j                  t        j                  j                        }|t
        z
  }t        |j                               }| j                  xs | j                  dz  }t        j                  ||      S )zReturn a timestamp message.

        Returns:
            (:class:`~google.protobuf.timestamp_pb2.Timestamp`): Timestamp message
        r   r   )secondsr$   )r   r   r   rJ   rK   r   rC   total_secondsr   r   r   	Timestamp)r(   r%   deltarS   r$   s        r
   timestamp_pbz$DatetimeWithNanoseconds.timestamp_pb   s     {{& X%6%6%:%:; 	
 z!e))+,  ;D$4$4t$;&&weDDr   c           
      $   t        |j                  dz        }t        |      } | |j                  |j                  |j
                  |j                  |j                  |j                  |j                  t        j                  j                        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;   )rC   rS   r   rD   rE   rF   rG   rH   rI   r$   r   rJ   rK   )r!   rL   r   rN   s       r
   from_timestamp_pbz)DatetimeWithNanoseconds.from_timestamp_pb   sn     5==3./!,/IIJJHHIIKKKK{{$$((	
 		
r   )__name__
__module____qualname____doc__	__slots__r    r   propertyr   r7   classmethodrQ   rW   rY   __classcell__)r-   s   @r
   r   r   L   sc    
 !I D ; ;	K &
 &
PE  
 
r   r   )T)r]   calendarr   regoogle.protobufr   fromtimestamprJ   rK   r   r   r6   compileVERBOSEr<   r   r   r    r   r
   <module>ri      s    #   	 ) ,,Q0A0A0E0EF
)* 	 JJ
?+&U
h// U
r   