Skip to content

Commit

Permalink
if end date is today, include today
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydeluca committed Oct 22, 2024
1 parent 898b2f5 commit e203367
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
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

0 comments on commit e203367

Please sign in to comment.