Skip to content

Commit

Permalink
Fix first day of year edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
ColeFrench committed Aug 12, 2024
1 parent 31b09af commit a7e5c86
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion metrics_layer/core/model/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,12 @@ def _parse_n_interval_modifier(date_condition: str, interval_condition: str, tz:
# We need to figure out how many days are between now and the start of the period
start_of_period = Filter._start_date(lag=0, date_part=date_part, tz=tz, return_date=True)
time_change = Filter._today(tz=tz) - start_of_period
lag = time_change.days - 1 if time_change.days > 0 else 0
if date_part == "year" and time_change.days == 0:
lag = -1
elif time_change.days > 0:
lag = time_change.days - 1
else:
lag = 0
end_date = Filter._add_to_end_date(start_date, lag=lag, date_part="day")
result.append((end_expression, Filter._date_to_string(end_date)))

Expand Down

0 comments on commit a7e5c86

Please sign in to comment.