U
    T?h=                     @   s   d Z ddlZddlmZ ddlmZ eedddZeedd	d
Z	eedddZ
eedddZeedddZedddZeedddZeedddZeedddZeedddZeedd d!Zd%eeej ejd"d#d$ZdS )&z#Contains the Timestamp helper APIs.    N)Optional)	Timestamp)valuereturnc                 C   s   t  }||  |S )a<  Parse a RFC 3339 date string format to Timestamp.

  Args:
    value: A date string. Any fractional digits (or none) and any offset are
      accepted as long as they fit into nano-seconds precision. Example of
      accepted format: '1972-01-01T10:00:20.021-05:00'

  Raises:
    ValueError: On parsing problems.
  )r   ZFromJsonString)r   	timestamp r   K/var/www/html/venv/lib/python3.8/site-packages/google/protobuf/timestamp.pyfrom_json_string   s    
r	   )microsr   c                 C   s   t  }||  |S )z/Converts microseconds since epoch to Timestamp.)r   ZFromMicroseconds)r
   r   r   r   r   from_microseconds    s    
r   )millisr   c                 C   s   t  }||  |S )z/Converts milliseconds since epoch to Timestamp.)r   ZFromMilliseconds)r   r   r   r   r   from_milliseconds'   s    
r   )nanosr   c                 C   s   t  }||  |S )z.Converts nanoseconds since epoch to Timestamp.)r   ZFromNanoseconds)r   r   r   r   r   from_nanoseconds.   s    
r   )secondsr   c                 C   s   t  }||  |S )z*Converts seconds since epoch to Timestamp.)r   ZFromSeconds)r   r   r   r   r   from_seconds5   s    
r   )r   c                  C   s"   t  } | tjjtjjd | S )z&Converts the current UTC to Timestamp.)tz)r   ZFromDatetimedatetimenowtimezoneutc)r   r   r   r   from_current_time<   s    r   )tsr   c                 C   s   |   S )a  Converts Timestamp to RFC 3339 date string format.

  Returns:
    A string converted from timestamp. The string is always Z-normalized
    and uses 3, 6 or 9 fractional digits as required to represent the
    exact time. Example of the return format: '1972-01-01T10:00:20.021Z'
  )ZToJsonStringr   r   r   r   to_json_stringC   s    r   c                 C   s   |   S )z/Converts Timestamp to microseconds since epoch.)ZToMicrosecondsr   r   r   r   to_microsecondsN   s    r   c                 C   s   |   S )z/Converts Timestamp to milliseconds since epoch.)ZToMillisecondsr   r   r   r   to_millisecondsS   s    r   c                 C   s   |   S )z.Converts Timestamp to nanoseconds since epoch.)ZToNanosecondsr   r   r   r   to_nanosecondsX   s    r   c                 C   s   |   S )z*Converts Timestamp to seconds since epoch.)Z	ToSecondsr   r   r   r   
to_seconds]   s    r   )r   r   r   c                 C   s   | j |dS )a7  Converts Timestamp to a datetime.

  Args:
    tz: A datetime.tzinfo subclass; defaults to None.

  Returns:
    If tzinfo is None, returns a timezone-naive UTC datetime (with no timezone
    information, i.e. not aware that it's UTC).

    Otherwise, returns a timezone-aware datetime in the input timezone.
  )tzinfo)Z
ToDatetime)r   r   r   r   r   to_datetimeb   s    r    )N)__doc__r   typingr   Zgoogle.protobuf.timestamp_pb2r   strr	   floatr   r   r   r   r   r   intr   r   r   r   r   r    r   r   r   r   <module>   s(     