From e2033676c62ee9fb4804454bee332c0a2bd0b146 Mon Sep 17 00:00:00 2001 From: Jay DeLuca Date: Tue, 22 Oct 2024 06:39:36 -0400 Subject: [PATCH] if end date is today, include today --- tests/test_utilities.py | 26 ++++++++++++++------------ utilities.py | 8 ++++++-- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index b004bb4..145e38d 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -9,12 +9,13 @@ def test_get_dates_since(self): start = "2023-01-01" end_date = datetime.strptime("2023-01-30", '%Y-%m-%d').date() interval = 7 - expected = ['2023-01-01T00:00:00Z', - '2023-01-08T00:00:00Z', - '2023-01-15T00:00:00Z', - '2023-01-22T00:00:00Z', - '2023-01-29T00:00:00Z' - ] + expected = { + '2023-01-01T00:00:00Z', + '2023-01-08T00:00:00Z', + '2023-01-15T00:00:00Z', + '2023-01-22T00:00:00Z', + '2023-01-29T00:00:00Z' + } result = get_dates_between(start, end_date, interval) @@ -24,12 +25,13 @@ def test_get_dates_between_given_end_date_as_string_converts_to_date(self): start = "2023-01-01" end_date = "2023-01-30" interval = 7 - expected = ['2023-01-01T00:00:00Z', - '2023-01-08T00:00:00Z', - '2023-01-15T00:00:00Z', - '2023-01-22T00:00:00Z', - '2023-01-29T00:00:00Z' - ] + expected = { + '2023-01-01T00:00:00Z', + '2023-01-08T00:00:00Z', + '2023-01-15T00:00:00Z', + '2023-01-22T00:00:00Z', + '2023-01-29T00:00:00Z' + } result = get_dates_between(start, end_date, interval) diff --git a/utilities.py b/utilities.py index 6cdf4e3..c98e37e 100644 --- a/utilities.py +++ b/utilities.py @@ -20,11 +20,15 @@ def get_dates_between(start_date_str, end_date, interval): days_diff = (end_date - start_date).days # Generate the list of dates - date_list = [] + date_list = set() for i in range(0, days_diff + 1, int(interval)): date_item = start_date + timedelta(days=i) start_date_str = date_item.strftime(output_format) - date_list.append(start_date_str) + date_list.add(start_date_str) + + # include end of today in the set if end_date is today + if end_date == datetime.now().date(): + date_list.add((datetime.now() + timedelta(days=1)).strftime(output_format)) return date_list