
                             S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKrSSKrSSK	J
r
  S rS rS	 rS
 rS rS rS rg)zjA module for capturing time-related functions.

This makes mocking for time-related functionality easier.
    )absolute_import)division)unicode_literalsN)mapc                  ,    [         R                   " 5       $ )z/Returns a float of the current time in seconds.)time     0lib/googlecloudsdk/command_lib/util/time_util.pyCurrentTimeSecr       s    	r
   c                 0    [         R                  " U 5        g)zSleeps for the given duration.N)r   sleep)duration_secs    r   Sleepr   %   s    **\r
   c                  >    [         R                   R                  5       $ )z6Returns the current date and time in the UTC timezone.)datetimeutcnowr	   r
   r   CurrentDatetimeUtcr   *   s    				!	!	##r
   c                 H    SnX:X  a  g[        U 5      nU[        5       :  a  gg)N FT)Strptimer   )timestamp_rfc3993_strno_expirationtimestamp_unixs      r   	IsExpiredr   /   s,    -+12.n&&	r
   c                    [         R                  " SU 5      nU(       d  [        SU -  5      eUR                  5       u  p#pEpgnpp[	        [        [        X#XEXg/5      5      nU	S:X  a  SnO&[        U5      S-  [        U5      S-  -   nU
S:X  a  U* n[        R                  " U5      U-
  nU(       a&  [        U5      nUSU-  -  [        U5      -   SU* -  -  $ U$ )	a_  Converts an RFC 3339 timestamp to Unix time in seconds since the epoch.

Args:
  rfc3339_str: a timestamp in RFC 3339 format (yyyy-mm-ddThh:mm:ss.sss
      followed by a time zone, given as Z, +hh:mm, or -hh:mm)

Returns:
  a number of seconds since January 1, 1970, 00:00:00 UTC

Raises:
  ValueError: if the timestamp is not in an acceptable format
zT(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.(\d+))?(?:(Z)|([-+])(\d\d):(\d\d))znot a valid timestamp: %rZr   i  <   -
   )
rematch
ValueErrorgroupslistr   intcalendartimegmlen)rfc3339_strr"   yearmonthdayhourminutesecondfrac_secondszulu	zone_sign
zone_hourszone_minutes
time_tuplezone_offsetinteger_timesig_digs                    r   r   r   9   s     (( 23>@% 

0;>
?? 16.46<JCd3fEFG* 
S[Kj/D(3|+<r+AAKC Lk,{:,,GR7]+< !%'G8^5 6 r
   c                 ~    U c  g[        5       nU[        R                  " S[        U 5      5      -   n[	        U5      nU$ )zFTakes a number of seconds and returns the expiration time in RFC 3339.Nr   )r   r   	timedeltar&   _FormatDateString)num_secondsutc_nowadjustedformatted_expirations       r   CalculateExpirationrA   b   s@     'x))!S-=>>(*84	r
   c                     SU R                   U R                  U R                  U R                  U R                  U R
                  4-  $ )Nz%04d-%02d-%02dT%02d:%02d:%02dZ)r+   r,   r-   r.   r/   r0   )ds    r   r<   r<   m   s8    
*66177AEE166188QXX
>? @r
   )__doc__
__future__r   r   r   r'   r   r!   r   	six.movesr   r   r   r   r   r   rA   r<   r	   r
   r   <module>rG      sI   
 '  '   	  

$
&R@r
   