Handle "tonight" and text containing only a date

- "tonight" is re-interpreted as PM
- check is performed to check if previous word exist before accessing it
to handle sentences containing only a simple date
pull/1307/head
Åke Forslund 2017-12-12 08:35:13 +01:00
parent 7b091e9b46
commit 01b37f06eb
1 changed files with 5 additions and 2 deletions

View File

@ -379,8 +379,8 @@ def extract_datetime_en(str, currentDate=None):
m = monthsShort.index(word)
used += 1
datestr = months[m]
if wordPrev[0].isdigit() or \
(wordPrev == "of" and wordPrevPrev[0].isdigit()):
if wordPrev and (wordPrev[0].isdigit() or
(wordPrev == "of" and wordPrevPrev[0].isdigit())):
if wordPrev == "of" and wordPrevPrev[0].isdigit():
datestr += " " + words[idx - 2]
used += 1
@ -542,6 +542,9 @@ def extract_datetime_en(str, currentDate=None):
if nextWord == "am" or nextWord == "pm":
remainder = nextWord
used += 1
elif nextWord == "tonight":
remainder = "pm"
used += 1
elif wordNext == "in" and wordNextNext == "the" and \
words[idx + 3] == "morning":
reaminder = "am"