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
commit 2cf52e25b5

View File

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