Skip to content

Commit 8af2faa

Browse files
committed
change(datetimes): get_current_week_of accepts the date to base the calculation on
1 parent 1993645 commit 8af2faa

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

iarp_utils/datetimes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def iterate_steps_between_datetimes(start, end, steps):
5555
start += steps
5656

5757

58-
def get_current_week_of(weekday_number):
58+
def get_current_week_of(weekday_number, date=datetime.datetime.today):
5959
""" Returns the last date of the weekday_number supplied.
6060
6161
i.e. I always need Thursdays but if today isn't Thursday,
@@ -68,12 +68,13 @@ def get_current_week_of(weekday_number):
6868
Args:
6969
weekday_number: The weekday index (Monday = 0)
7070
that we're basing our week on.
71+
date: The date to base it on.
7172
7273
Returns:
7374
date object
7475
7576
"""
76-
today = datetime.datetime.today()
77+
today = date()
7778

7879
offset = (today.weekday() - weekday_number) % 7
7980

0 commit comments

Comments
 (0)