Skip to content

Commit

Permalink
address comment and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devketanpro committed May 15, 2024
1 parent 2e61557 commit 7ee51a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 4 additions & 4 deletions server/planning/search/queries/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,23 @@ def __init__(

def start_of_this_week(start_of_week=0, date=None):
start = get_start_of_next_week(date, start_of_week) - timedelta(days=7)
return start.strftime("%Y-%m-%d") + "||/d"
return start.isoformat()


def end_of_this_week(start_of_week=0, date=None):
end = get_start_of_next_week(date, start_of_week) - timedelta(start_of_week)
return end.strftime("%Y-%m-%d") + "||/d"
return end.isoformat()


def start_of_next_week(start_of_week=0, date=None):
return get_start_of_next_week(date, start_of_week).strftime("%Y-%m-%d") + "||/d"
return get_start_of_next_week(date, start_of_week).isoformat()


def end_of_next_week(start_of_week=0, date=None):
start = get_start_of_next_week(date, start_of_week)
end = start + timedelta(days=7)

return end.strftime("%Y-%m-%d") + "||/d"
return end.isoformat()


def bool_or(conditions: List[Dict[str, Any]]):
Expand Down
13 changes: 11 additions & 2 deletions server/planning/tests/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def test_dates_same_and_different_time(self):

class TestDateRangeFunctions(TestCase):
def get_start_date_and_weekday(self, start_date_str):
start_date = datetime.strptime(start_date_str.split("||")[0], "%Y-%m-%d")
return start_date.weekday()
start_date = datetime.fromisoformat(start_date_str).weekday()
return start_date

def test_start_of_next_week(self):
# Test with default start_of_week
Expand All @@ -62,3 +62,12 @@ def test_end_of_next_week(self):
end_date_str = elastic.end_of_next_week(date=start_date, start_of_week=1)
expected_weekday = self.get_start_date_and_weekday(end_date_str)
self.assertEqual(expected_weekday, 0) # Monday

def test_events_within_current_week(self):
# Test events that start and end within the current week
start_date = datetime(2024, 5, 15) # Assuming today is May 15, 2024 (Wed)
start = elastic.start_of_this_week(date=start_date, start_of_week=1)
end = elastic.end_of_this_week(date=start_date, start_of_week=1)

self.assertEqual(start, "2024-05-13T00:00:00")
self.assertEqual(end, "2024-05-19T00:00:00")

0 comments on commit 7ee51a1

Please sign in to comment.