Skip to content

Commit

Permalink
fix: rocketry.time.RelativeDay
Browse files Browse the repository at this point in the history
This is not used anywhere.
  • Loading branch information
Miksus committed Jul 12, 2022
1 parent ab85058 commit 840463d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
25 changes: 25 additions & 0 deletions rocketry/test/time/interval/test_relative_day.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import datetime
import pytest
from rocketry.time import RelativeDay

@pytest.mark.parametrize("day,left,right", [
pytest.param('today', datetime.datetime(2022, 5, 15), datetime.datetime(2022, 5, 15, 23, 59, 59, 999999)),
])
def test_rollback(day, left, right):
rel_day = RelativeDay(day)

dt = datetime.datetime(2022, 5, 15)
interval = rel_day.rollback(dt)
assert interval.left == left
assert interval.right == right


def test_rollforward():
rel_day = RelativeDay("today")
with pytest.raises(AttributeError):
interval = rel_day.rollforward(datetime.datetime(2022, 5, 15))


def test_repr():
rel_day = RelativeDay("today")
repr(rel_day)
14 changes: 9 additions & 5 deletions rocketry/time/interval.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import calendar
import datetime
import re

import dateutil
Expand Down Expand Up @@ -298,16 +299,19 @@ class RelativeDay(TimeInterval):
"""

offsets = {
"today": pd.Timedelta("0 day"),
"yesterday": pd.Timedelta("1 day"),
"the_day_before": pd.Timedelta("2 day"),
"today": datetime.timedelta(),
"yesterday": datetime.timedelta(days=1),
"the_day_before":datetime.timedelta(days=2),
#"first_day_of_year": get_first_day_of_year,
}

min_time = datetime.time.min
max_time = datetime.time.max

def __init__(self, day, *, start_time=None, end_time=None):
self.day = day
self.start_time = self.min.date() if start_time is None else start_time
self.end_time = self.max.date() if end_time is None else end_time
self.start_time = self.min_time if start_time is None else start_time
self.end_time = self.max_time if end_time is None else end_time

def rollback(self, dt):
offset = self.offsets[self.day]
Expand Down

0 comments on commit 840463d

Please sign in to comment.