From f8bc0fbf5e40b06920e255a9525e159169a23eb8 Mon Sep 17 00:00:00 2001 From: Andrew Melton Date: Thu, 14 Feb 2013 15:27:02 -0500 Subject: [PATCH] Improving str_time_to_unix() --- stacktach/views.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/stacktach/views.py b/stacktach/views.py index d770645..10e6a6d 100644 --- a/stacktach/views.py +++ b/stacktach/views.py @@ -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)