Merge pull request #33 from ramielrowe/master
Improving str_time_to_unix()
This commit is contained in:
commit
2cf52e25b5
@ -321,17 +321,25 @@ def aggregate_usage(raw):
|
|||||||
|
|
||||||
|
|
||||||
def str_time_to_unix(when):
|
def str_time_to_unix(when):
|
||||||
try:
|
if 'T' in when:
|
||||||
when = datetime.datetime.strptime(when, "%Y-%m-%d %H:%M:%S")
|
try:
|
||||||
except ValueError:
|
# 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:
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user