utils.py
changeset 89 2dc6de43f317
parent 73 5a7188bf2894
child 95 ebdbda3dd5d0
equal deleted inserted replaced
88:0b8e2ba5f76f 89:2dc6de43f317
    65 
    65 
    66     def parse (self, timestamp_str) :
    66     def parse (self, timestamp_str) :
    67         """
    67         """
    68             timestamp_str -> pytz.utc datetime.datetime
    68             timestamp_str -> pytz.utc datetime.datetime
    69         """
    69         """
    70 
    70         
    71         return datetime.datetime.utcfromtimestamp(int(timestamp_str)).replace(tzinfo=pytz.utc)
    71         return from_utc_timestamp(int(timestamp_str))
    72     
    72     
    73     def build (self, dtz) :
    73     def build (self, dtz) :
    74         """
    74         """
    75             pytz.utc datetime.datetime -> timestamp_str
    75             pytz.utc datetime.datetime -> timestamp_str
    76         """
    76         """
       
    77         
       
    78         return str(to_utc_timestamp(dtz))
    77 
    79 
    78         return str(calendar.timegm(dtz.utctimetuple()))
    80 def from_utc_timestamp (timestamp) :
       
    81     """
       
    82         Converts a UNIX timestamp into a datetime.datetime
       
    83     """
    79 
    84 
       
    85     return datetime.datetime.utcfromtimestamp(timestamp).replace(tzinfo=pytz.utc)
       
    86 
       
    87 def to_utc_timestamp (dt) :
       
    88     """
       
    89         Converts a datetime.datetime into a UNIX timestamp
       
    90     """
       
    91 
       
    92     return calendar.timegm(dt.utctimetuple())
       
    93