From c17ffc1e9c4c2ad7bfaae430c0bf00f9d46e52f4 Mon Sep 17 00:00:00 2001 From: Emanuele Cesena Date: Thu, 10 Aug 2017 23:04:49 -0700 Subject: [PATCH] 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 ed841862ea7..cd70e0c066a 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))