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):
|
||||
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)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user