diff --git a/mycroft/util/lang/parse_en.py b/mycroft/util/lang/parse_en.py index 2149ec0758..c0e4bed559 100644 --- a/mycroft/util/lang/parse_en.py +++ b/mycroft/util/lang/parse_en.py @@ -741,7 +741,7 @@ def extract_datetime_en(string, dateNow, default_time): timeQualifier = "" timeQualifiersAM = ['morning'] - timeQualifiersPM = ['afternoon', 'evening', 'tonight', 'night'] + timeQualifiersPM = ['afternoon', 'evening', 'night'] timeQualifiersList = set(timeQualifiersAM + timeQualifiersPM) markers = ['at', 'in', 'on', 'by', 'this', 'around', 'for', 'of', "within"] days = ['monday', 'tuesday', 'wednesday', @@ -749,6 +749,8 @@ def extract_datetime_en(string, dateNow, default_time): months = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'] + recur_markers = days + [d+'s' for d in days] + ['weekend', 'weekday', + 'weekends', 'weekdays'] monthsShort = ['jan', 'feb', 'mar', 'apr', 'may', 'june', 'july', 'aug', 'sept', 'oct', 'nov', 'dec'] year_multiples = ["decade", "century", "millennium"] @@ -815,6 +817,9 @@ def extract_datetime_en(string, dateNow, default_time): elif word == "today" and not fromFlag: dayOffset = 0 used += 1 + elif word == "tonight" and not fromFlag: + dayOffset = 0 + used += 1 elif word == "tomorrow" and not fromFlag: dayOffset = 1 used += 1 @@ -1165,6 +1170,15 @@ def extract_datetime_en(string, dateNow, default_time): strHH = strNum remainder = "am" used = 1 + elif ( + remainder in recur_markers or + wordNext in recur_markers or + wordNextNext in recur_markers): + # Ex: "7 on mondays" or "3 this friday" + # Set strHH so that isTime == True + # when am or pm is not specified + strHH = strNum + used = 1 else: if ( int(strNum) > 100 and diff --git a/test/unittests/util/test_parse.py b/test/unittests/util/test_parse.py index 7d2f55ddd5..0112b73028 100644 --- a/test/unittests/util/test_parse.py +++ b/test/unittests/util/test_parse.py @@ -455,6 +455,20 @@ class TestNormalize(unittest.TestCase): "2017-07-08 10:00:00", "remind me to call mom") testExtract("remind me to call mom at 10am next saturday", "2017-07-08 10:00:00", "remind me to call mom") + # Below two tests, ensure that time is picked + # even if no am/pm is specified + # in case of weekdays/tonight + testExtract("set alarm for 9 on weekdays", + "2017-06-27 21:00:00", "set alarm weekdays") + testExtract("for 8 tonight", + "2017-06-27 20:00:00", "") + testExtract("for 8:30pm tonight", + "2017-06-27 20:30:00", "") + # Tests a time with ':' & without am/pm + testExtract("remind me about the game tonight at 11:30", + "2017-06-27 23:30:00", "remind me about game") + testExtract("set alarm at 7:30 on weekdays", + "2017-06-27 19:30:00", "set alarm on weekdays") def test_extract_ambiguous_time_en(self): morning = datetime(2017, 6, 27, 8, 1, 2)