U
    #FZh?                     @   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                   @   s8   e Zd ZdZddeejdddZej	d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absentr   returnc                C   s$   t |tjr |rd S tj|S |S )N)
isinstancer   	Timestampr   DatetimeWithNanosecondsZfrom_timestamp_pbselfvaluer    r   `/home/aprabhat/apps/x.techxrdev.in/venv/lib/python3.8/site-packages/proto/marshal/rules/dates.py	to_python!   s
    zTimestampRule.to_pythonr   c                 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                   @   s6   e Zd ZdZddeedddZejd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   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_pythonr   c                 C   sP   t |tr*tj|jd |j |jd dS t |trLt }|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   !