-
Notifications
You must be signed in to change notification settings - Fork 67
Leonlu2/inequality issue time value #1124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
7536ca3
51cb58e
3a9c7e7
81762b8
0c1d876
896e409
cab9514
8df74aa
d2663e2
f66b2e3
22b4de7
6f4feab
3e30693
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -403,11 +403,12 @@ def _parse_range(part: str): | |
|
||
def parse_date(s: str) -> int: | ||
# parses a given string in format YYYYMMDD or YYYY-MM-DD to a number in the form YYYYMMDD | ||
if s == "*": | ||
return s | ||
if not s: | ||
raise ValidationFailedException("not a valid date: (empty)") | ||
try: | ||
if s == "*": | ||
return s | ||
else: | ||
return int(s.replace("-", "")) | ||
return int(s.replace("-", "")) | ||
except ValueError: | ||
raise ValidationFailedException(f"not a valid date: {s}") | ||
|
||
|
@@ -425,6 +426,17 @@ def extract_dates(key: Union[str, Sequence[str]]) -> Optional[TimeValues]: | |
return None | ||
values: TimeValues = [] | ||
|
||
def handle_inequality(part: str): | ||
inequality_operator = None | ||
for operator in ['<=', '>=', '<', '>']: | ||
if part.startswith(operator): | ||
inequality_operator = operator | ||
part = part[len(operator):] | ||
if not part: | ||
raise ValidationFailedException("missing parameter: date after the inequality operator") | ||
return (inequality_operator,), part | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: using a length-1 tuple here feels weird later on we're using the tuple type information to engage the inequalities logic instead of the range logic, so it's clearly needed, but it feels unsatisfying regardless There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hey @rzats do you have any ideas for how we can more clearly indicate that a date parameter value is an inequality? the return value from this function is read in the date span processing at _query.py:45, dates.py:125, and dates.py:147, where inequalities need to be handled differently from other kinds of spans. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I can see what this PR is going for and there might be a better way to handle the inequalities. Right now this is returning a single-element tuple to fit within the following type structure;
A clean solution would be to add a new type alias called
|
||
return None, part | ||
|
||
def push_range(first: str, last: str): | ||
first_d = parse_date(first) | ||
last_d = parse_date(last) | ||
|
@@ -438,6 +450,12 @@ def push_range(first: str, last: str): | |
raise ValidationFailedException(f"{key}: the given range is inverted") | ||
|
||
for part in parts: | ||
# Handle inequality operators | ||
inequality_operator, part = handle_inequality(part) | ||
# >/</>=/<= YYYYMMDD/YYYY-MM-DD | ||
if inequality_operator is not None: | ||
values.append((inequality_operator, parse_date(part))) | ||
continue | ||
if "-" not in part and ":" not in part: | ||
# YYYYMMDD | ||
values.append(parse_date(part)) | ||
|
Uh oh!
There was an error while loading. Please reload this page.