o
    uZh?                     @   sl   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 d dlmZmZ G dd dZ	G d	d
 d
Z
dS )    )datetime)	timedelta)timezone)duration_pb2)timestamp_pb2)datetime_helpersutilsc                   @   s:   e Zd ZdZdddedejfddZdej	fd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                C   s$   t |tjr|r
d S tj|S |S )N)
isinstancer   	Timestampr   DatetimeWithNanosecondsZfrom_timestamp_pbselfvaluer    r   P/var/www/html/lang_env/lib/python3.10/site-packages/proto/marshal/rules/dates.py	to_python!   s
   zTimestampRule.to_pythonc                 C   s`   t |tjr
| S t |trtjt| |j	d dS t |t
r.t }|j|d |S |S )N  secondsnanosr   )r   r   r   Ztimestamp_pbr   r   r   int	timestampmicrosecondstrFromJsonString)r   r   Ztimestamp_valuer   r   r   to_proto*   s   


zTimestampRule.to_proto)__name__
__module____qualname____doc__boolr   r   r   r   r   r    r   r   r   r   r	      s    	
	r	   c                   @   s8   e Zd ZdZdddedefddZdejfd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                C   s0   t |tjrt|jd |jd |jd dS |S )NQ r   )daysr   microseconds)r   r   Durationr   r   r   r   r   r   r   r   B   s   zDurationRule.to_pythonc                 C   sP   t |trtj|jd |j |jd dS t |tr&t }|j|d |S |S )Nr'   r   r   r   )	r   r   r   r*   r(   r   r)   r   r   )r   r   Zduration_valuer   r   r   r    K   s   

zDurationRule.to_proto)
r!   r"   r#   r$   r%   r   r   r   r*   r    r   r   r   r   r&   9   s    	r&   N)r   r   r   Zgoogle.protobufr   r   protor   r   r	   r&   r   r   r   r   <module>   s   !