superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: Fix returned time parse_human_datetime (#2033)
Date Fri, 11 Aug 2017 06:04:51 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new c17ffc1  Fix returned time parse_human_datetime (#2033)
c17ffc1 is described below

commit c17ffc1e9c4c2ad7bfaae430c0bf00f9d46e52f4
Author: Emanuele Cesena <emanuele.cesena@gmail.com>
AuthorDate: Thu Aug 10 23:04:49 2017 -0700

    Fix returned time parse_human_datetime (#2033)
    
    parse_human_datetime parses date-only strings, e.g. "today", returning the correct date
but time set at 9am. This is an internal implementation in parsedatetime. This patch resets
to midnight. If time is specified and parsed, it is correctly returned.
---
 superset/utils.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/superset/utils.py b/superset/utils.py
index ed84186..cd70e0c 100644
--- a/superset/utils.py
+++ b/superset/utils.py
@@ -203,7 +203,11 @@ def parse_human_datetime(s):
     except Exception:
         try:
             cal = parsedatetime.Calendar()
-            dttm = dttm_from_timtuple(cal.parse(s)[0])
+            parsed_dttm, parsed_flags = cal.parseDT(s)
+            # when time is not extracted, we "reset to midnight"
+            if parsed_flags & 2 == 0:
+                parsed_dttm = parsed_dttm.replace(hour=0, minute=0, second=0)
+            dttm = dttm_from_timtuple(parsed_dttm.utctimetuple())
         except Exception as e:
             logging.exception(e)
             raise ValueError("Couldn't parse date string [{}]".format(s))

-- 
To stop receiving notification emails like this one, please contact
['"commits@superset.apache.org" <commits@superset.apache.org>'].

Mime
View raw message