Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if end date is today, include today #13

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
8 changes: 6 additions & 2 deletions utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading