fix name error
[sfa.git] / sfa / util / sfatime.py
index c5c6a55..478c5be 100644 (file)
@@ -5,6 +5,8 @@ import time
 
 from sfa.util.sfalogging import logger
 
+DATEFORMAT = "%Y-%m-%dT%H:%M:%SZ"
+
 def utcparse(input):
     """ Translate a string into a time using dateutil.parser.parse but make sure it's in UTC time and strip
 the timezone, so that it's compatible with normal datetime.datetime objects.
@@ -20,10 +22,19 @@ For safety this can also handle inputs that are either timestamps, or datetimes
         if t.utcoffset() is not None:
             t = t.utcoffset() + t.replace(tzinfo=None)
         return t
-    elif isinstance (input, (int,float)):
+    elif isinstance (input, (int,float,long)):
         return datetime.datetime.fromtimestamp(input)
     else:
         logger.error("Unexpected type in utcparse [%s]"%type(input))
 
-def epochparse(input):
-    return time.strftime("%Y-%d-%m-T%H:%M:%SZ", time.localtime(input)) 
+def datetime_to_string(input):
+    return datetime.datetime.strftime(input, DATEFORMAT)
+
+def datetime_to_utc(input):
+    return time.gmtime(datetime_to_epoch(input))    
+
+def datetime_to_epoch(input):
+    return time.mktime(input.timetuple())
+
+
+