
    ci                     h    d dl m Z  d dl mZ d dlmZ d dlmZ d dlmZ  G d d      Z G d d	      Zy
)    )datetime)	timedelta)duration_pb2)timestamp_pb2)datetime_helpersc                   Z    e Zd ZdZdddedej                  fdZdej                  fdZ
y)TimestampRulea&  A marshal between Python datetimes and protobuf timestamps.

    Note: Python datetimes are less precise than protobuf datetimes
    (microsecond vs. nanosecond level precision). If nanosecond-level
    precision matters, it is recommended to interact with the internal
    proto directly.
    Nabsentr   returnc                ~    t        |t        j                        r"|ry t        j                  j                  |      S |S )N)
isinstancer   	Timestampr   DatetimeWithNanosecondsfrom_timestamp_pbselfvaluer   s      ]/var/www/html/spbu.com/backend/venv/lib/python3.12/site-packages/proto/marshal/rules/dates.py	to_pythonzTimestampRule.to_python    s6     e]445#;;MMeTT    c                 `   t        |t        j                        r|j                         S t        |t              r;t        j                  t        |j                               |j                  dz        S t        |t              r(t        j                         }|j                  |       |S |S )N  secondsnanosr   )r   r   r   timestamp_pbr   r   r   int	timestampmicrosecondstrFromJsonString)r   r   timestamp_values      r   to_protozTimestampRule.to_proto)   s    e-EEF%%''eX& **EOO-.''$.  eS!+557O***7""r   )__name__
__module____qualname____doc__boolr   r   r   r   r   r%    r   r   r	   r	      s9     (, $		1	1!8!8 r   r	   c                   F    e Zd ZdZdddedefdZdej                  fdZ	y)DurationRulea'  A marshal between Python timedeltas and protobuf durations.

    Note: Python timedeltas are less precise than protobuf durations
    (microsecond vs. nanosecond level precision). If nanosecond-level
    precision matters, it is recommended to interact with the internal
    proto directly.
    Nr
   r   r   c                    t        |t        j                        r5t        |j                  dz  |j                  dz  |j
                  dz        S |S )NQ r   )daysr   microseconds)r   r   Durationr   r   r   r   s      r   r   zDurationRule.to_pythonA   sJ    e\223]]e+-"[[D0 
 r   c                    t        |t              r>t        j                  |j                  dz  |j
                  z   |j                  dz        S t        |t              r(t        j                         }|j                  |       |S |S )Nr/   r   r   r   )	r   r   r   r2   r0   r   r1   r"   r#   )r   r   duration_values      r   r%   zDurationRule.to_protoJ   sx    eY'((

U*U]]:((4/  eS!)224N)))6!!r   )
r&   r'   r(   r)   r*   r   r   r   r2   r%   r+   r   r   r-   r-   8   s1     26 $ ) 
!6!6 
r   r-   N)	r   r   google.protobufr   r   protor   r	   r-   r+   r   r   <module>r7      s+      ( ) " B r   