| nthWeekdayInMonthMaybeYearExpr
| firstLastWeekdayInMonthMaybeYearExpr
| deltaDateExprRelativeToTodayImplied
+ | dayName (SPACE|ddiv)+ monthDayMaybeYearExpr (SPACE|ddiv)* singleTimeExpr*
| dayName
;
return 5
def _parse_normal_date(self) -> datetime.date:
- if 'dow' in self.context:
+ if 'dow' in self.context and 'month' not in self.context:
d = self.today
while d.weekday() != self.context['dow']:
d += datetime.timedelta(days=1)
return None
+def extract_date(in_str: Any) -> Optional[str]:
+ import itertools
+
+ import dateparse.dateparse_utils as du
+
+ d = du.DateParser() # type: ignore
+ chunks = in_str.split()
+ for ngram in itertools.chain(
+ list_utils.ngrams(chunks, 5),
+ list_utils.ngrams(chunks, 4),
+ list_utils.ngrams(chunks, 3),
+ list_utils.ngrams(chunks, 2),
+ ):
+ try:
+ expr = " ".join(ngram)
+ logger.debug(f"Trying {expr}")
+ if d.parse(expr):
+ return d.get_date()
+ except du.ParseException: # type: ignore
+ pass
+ return None
+
+
def is_valid_date(in_str: str) -> bool:
"""
Args: