Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Garcia Reolid <victor@seita.nl>
  • Loading branch information
victorgarcia98 committed Mar 21, 2024
1 parent 641a210 commit 8f373c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions timely_beliefs/sensors/func_store/knowledge_horizons.py
Expand Up @@ -55,11 +55,16 @@ def x_years_ago_at_date(
These bounds are normally useful for creating more efficient database queries when filtering by belief time.
"""

if x < 0:
raise ValueError("Negative value for `x` not supported.")
MAX_DAYS_IN_A_YEAR = 366
MIN_DAYS_IN_A_YEAR = 366

if x <= 0:
raise ValueError("Only positive values for `x` are supported.")

if get_bounds:
return timedelta(days=(x - 1) * 366 - 3), timedelta(days=(x + 1) * 366 + 1)
# The minimum corresponds to an event at the 1st of January and a reference on the 31st of December on the the year `x` years ago.
# The maximum correponds to an event on the 31st of December and a reference on the 1st of January on the year `x` years ago.
return timedelta(days=(x - 1) * MIN_DAYS_IN_A_YEAR), timedelta(days=(x + 1) * MAX_DAYS_IN_A_YEAR + 1)

if isinstance(event_start, datetime):
return x_years_ago_at_date_datetime(event_start, day, month, x, z)
Expand Down
Expand Up @@ -152,7 +152,7 @@ def test_x_years_ago_at_date():
datetime(2024, 12, 31, 23, 59, 59, tzinfo=utc),
],
)
@pytest.mark.parametrize("year", list(range(6)))
@pytest.mark.parametrize("year", list(range(1,6)))
def test_x_years_ago_at_date_bounds(event_start, year):
knowledge_func_params = dict(month=12, day=31, x=year)

Expand Down

0 comments on commit 8f373c1

Please sign in to comment.