From 9c8c8e01440360694e3fd147d07f796d0a6b75f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Forslund?= Date: Wed, 29 Jan 2020 09:56:23 +0100 Subject: [PATCH] Send time reference for "now" to Lingua-franca This will provide timezone info as well as now reference to the extracted sentences. --- mycroft/util/parse.py | 4 ++-- test/unittests/util/test_parse.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mycroft/util/parse.py b/mycroft/util/parse.py index 689481928e..d37ec96eff 100644 --- a/mycroft/util/parse.py +++ b/mycroft/util/parse.py @@ -209,8 +209,8 @@ def extract_datetime(text, anchorDate=None, lang=None, default_time=None): ... ) None """ - ret = lingua_franca.parse.extract_datetime(text, anchorDate, lang, - default_time) + ret = lingua_franca.parse.extract_datetime(text, anchorDate or now_local(), + lang, default_time) # TODO: When default skills work with the documented behavour below needs # to be removed. diff --git a/test/unittests/util/test_parse.py b/test/unittests/util/test_parse.py index cf70507023..e919108f9a 100644 --- a/test/unittests/util/test_parse.py +++ b/test/unittests/util/test_parse.py @@ -26,6 +26,7 @@ from mycroft.util.parse import normalize from mycroft.util.lang.parse_en import _ReplaceableNumber, \ _extract_whole_number_with_text_en, _tokenize, _Token, \ _extract_decimal_with_text_en +from mycroft.util.time import default_timezone class TestFuzzyMatch(unittest.TestCase): @@ -144,6 +145,12 @@ class TestNormalize(unittest.TestCase): self.assertEqual(extract_number("a couple thousand beers"), 2000) self.assertEqual(extract_number("100%"), 100) + def test_extract_datetime(self): + """Check that extract_datetime returns the expected timezone.""" + tz = default_timezone() + dt, _ = extract_datetime("today") + self.assertEqual(tz, dt.tzinfo) + def test_extract_duration_en(self): self.assertEqual(extract_duration("10 seconds"), (timedelta(seconds=10.0), ""))