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.ces...@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
['"comm...@superset.apache.org" <comm...@superset.apache.org>'].

Reply via email to