
    \j                     v    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d
S )    )datetime)	timedelta)duration_pb2)timestamp_pb2)datetime_helpersc                   H    e Zd ZdZdddedej        fdZdej	        fdZ
dS )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d S t          j                            |          S |S )N)
isinstancer   	Timestampr   DatetimeWithNanosecondsfrom_timestamp_pbselfvaluer   s      ]/var/www/app.qaans.com/backend/venv/lib/python3.11/site-packages/proto/marshal/rules/dates.py	to_pythonzTimestampRule.to_python    sC     e]455 	U t#;MMeTTT    c                    t          |t          j                  r|                                S t          |t                    r=t          j        t          |                                          |j	        dz            S t          |t                    r+t          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FF 	(%%'''eX&& 	 *EOO--..'$.    eS!! 	#+577O***777""r   )__name__
__module____qualname____doc__boolr   r   r   r   r   r%    r   r   r	   r	      sr          (,   $		1   !8      r   r	   c                   >    e Zd ZdZdddedefdZdej        fdZ	dS )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                  r*t          |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   sS    e\23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                    }|                    |           |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   s    eY'' 	(
U*U]:(4/    eS!! 	")244N)))666!!r   )
r&   r'   r(   r)   r*   r   r   r   r2   r%   r+   r   r   r-   r-   8   sm          26   $ )    
!6 
 
 
 
 
 
r   r-   N)	r   r   google.protobufr   r   protor   r	   r-   r+   r   r   <module>r7      s                ( ( ( ( ( ( ) ) ) ) ) ) " " " " " "       B         r   