Merge pull request #33 from ramielrowe/master

Improving str_time_to_unix()
This commit is contained in:
Sandy Walsh
2013-02-14 12:29:06 -08:00

View File

@@ -321,17 +321,25 @@ def aggregate_usage(raw):
def str_time_to_unix(when): def str_time_to_unix(when):
if 'T' in when:
try: try:
when = datetime.datetime.strptime(when, "%Y-%m-%d %H:%M:%S") # Old way of doing it
when = datetime.datetime.strptime(when, "%Y-%m-%dT%H:%M:%S.%f")
except ValueError: except ValueError:
try:
# Old way of doing it, no millis
when = datetime.datetime.strptime(when, "%Y-%m-%dT%H:%M:%S")
except Exception, e:
print "BAD DATE: ", e
else:
try: try:
when = datetime.datetime.strptime(when, "%Y-%m-%d %H:%M:%S.%f") when = datetime.datetime.strptime(when, "%Y-%m-%d %H:%M:%S.%f")
except ValueError: except ValueError:
try: try:
# Old way of doing it when = datetime.datetime.strptime(when, "%Y-%m-%d %H:%M:%S")
when = datetime.datetime.strptime(when, "%Y-%m-%dT%H:%M:%S.%f")
except Exception, e: except Exception, e:
print "BAD DATE: ", e print "BAD DATE: ", e
return dt.dt_to_decimal(when) return dt.dt_to_decimal(when)