o
    ì6Wj  ã                   @   s\   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„ dƒZG dd	„ d	ƒZd
S )é    )Údatetime)Ú	timedelta)Úduration_pb2)Útimestamp_pb2)Údatetime_helpersc                   @   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   ÚDatetimeWithNanosecondsÚfrom_timestamp_pb©ÚselfÚvaluer	   © r   úh/home/esfera/Documents/content_generation/venv/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   Útimestamp_pbr   r   r   ÚintÚ	timestampÚmicrosecondÚstrÚFromJsonString)r   r   Ú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 )Né€Q r   )Údaysr   Úmicroseconds)r   r   ÚDurationr   r   r   r   r   r   r   r   A   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   Úduration_valuer   r   r   r!   J   s   
þ
zDurationRule.to_proto)
r"   r#   r$   r%   r&   r   r   r   r+   r!   r   r   r   r   r'   8   s    	r'   N)	r   r   Úgoogle.protobufr   r   Úprotor   r   r'   r   r   r   r   Ú<module>   s   !