Adding backwards compatable check to add ago to since if it doesn't exist (#6269)

This commit is contained in:
michellethomas
2018-11-05 16:30:04 -08:00
committed by Grace Guo
parent 7fe8e8aff2
commit c7f8abc6c5
2 changed files with 24 additions and 10 deletions

View File

@@ -923,6 +923,8 @@ def get_since_until(form_data):
time_range = form_data['time_range']
if separator in time_range:
since, until = time_range.split(separator, 1)
if since and since not in common_time_frames:
since = add_ago_to_since(since)
since = parse_human_datetime(since)
until = parse_human_datetime(until)
elif time_range in common_time_frames:
@@ -940,16 +942,29 @@ def get_since_until(form_data):
else:
since = form_data.get('since', '')
if since:
since_words = since.split(' ')
grains = ['days', 'years', 'hours', 'day', 'year', 'weeks']
if len(since_words) == 2 and since_words[1] in grains:
since += ' ago'
since = add_ago_to_since(since)
since = parse_human_datetime(since)
until = parse_human_datetime(form_data.get('until', 'now'))
return since, until
def add_ago_to_since(since):
"""
Backwards compatibility hack. Without this slices with since: 7 days will
be treated as 7 days in the future.
:param str since:
:returns: Since with ago added if necessary
:rtype: str
"""
since_words = since.split(' ')
grains = ['days', 'years', 'hours', 'day', 'year', 'weeks']
if (len(since_words) == 2 and since_words[1] in grains):
since += ' ago'
return since
def convert_legacy_filters_into_adhoc(fd):
mapping = {'having': 'having_filters', 'where': 'filters'}