Make date_filter.extract_date_range method always return a list type

This commit is contained in:
Debanjum Singh Solanky 2023-08-27 19:17:53 -07:00
parent d5a2de6222
commit 794bad8bcb
2 changed files with 7 additions and 7 deletions

View file

@ -63,7 +63,7 @@ class DateFilter(BaseFilter):
query_daterange = self.extract_date_range(query)
# if no date in query, return all entries
if query_daterange is None:
if query_daterange == []:
return query, set(range(len(entries)))
query = self.defilter(query)
@ -96,7 +96,7 @@ class DateFilter(BaseFilter):
date_range_matches = re.findall(self.date_regex, query)
if len(date_range_matches) == 0:
return None
return []
# extract, parse natural dates ranges from date range filter passed in query
# e.g today maps to (start_of_day, start_of_tomorrow)
@ -111,7 +111,7 @@ class DateFilter(BaseFilter):
# >=yesterday maps to [start_of_yesterday, inf)
# <tomorrow maps to [0, start_of_tomorrow)
# ---
effective_date_range = [0, inf]
effective_date_range: List = [0, inf]
date_range_considering_comparator = []
for cmp, (dtrange_start, dtrange_end) in date_ranges_from_filter:
if cmp == ">":
@ -136,7 +136,7 @@ class DateFilter(BaseFilter):
]
if effective_date_range == [0, inf] or effective_date_range[0] > effective_date_range[1]:
return None
return []
else:
return effective_date_range

View file

@ -68,13 +68,13 @@ def test_extract_date_range():
]
# Unparseable date filter specified in query
assert DateFilter().extract_date_range('head dt:"Summer of 69" tail') == None
assert DateFilter().extract_date_range('head dt:"Summer of 69" tail') == []
# No date filter specified in query
assert DateFilter().extract_date_range("head tail") == None
assert DateFilter().extract_date_range("head tail") == []
# Non intersecting date ranges
assert DateFilter().extract_date_range('head dt>"1984-01-01" dt<"1984-01-01" tail') == None
assert DateFilter().extract_date_range('head dt>"1984-01-01" dt<"1984-01-01" tail') == []
@pytest.mark.filterwarnings("ignore:The localize method is no longer necessary.")