Skip to content

Commit 0c86a43

Browse files
committed
Addressed pr comments
1 parent c751ad7 commit 0c86a43

File tree

2 files changed

+32
-43
lines changed

2 files changed

+32
-43
lines changed

tests_utils/test_date_time_utils.py

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,26 @@ def test_add_days():
3232
assert new_date == date + timedelta(days=5)
3333

3434

35-
def test_get_day_of_week_for_today():
35+
# Valid weekdays for testing get_day_of_week
36+
VALID_WEEKDAYS = [
37+
"Monday",
38+
"Tuesday",
39+
"Wednesday",
40+
"Thursday",
41+
"Friday",
42+
"Saturday",
43+
"Sunday",
44+
]
45+
46+
47+
def test_get_day_of_week_with_specific_date():
3648
dtu = utils.date_time_utils.DateTimeUtils()
37-
date = datetime.now()
38-
day_of_week = dtu.get_a_day_of_week(date)
39-
assert day_of_week in [
40-
"Monday",
41-
"Tuesday",
42-
"Wednesday",
43-
"Thursday",
44-
"Friday",
45-
"Saturday",
46-
"Sunday",
47-
]
48-
49-
50-
def test_get_a_day_of_week():
49+
date = datetime(2023, 11, 8) # Known Wednesday
50+
day_of_week = dtu.get_day_of_week(date)
51+
assert day_of_week in VALID_WEEKDAYS
52+
53+
54+
def test_get_day_of_week_with_default_today():
5155
dtu = utils.date_time_utils.DateTimeUtils()
52-
date = datetime(2023, 11, 8)
53-
day_of_week = dtu.get_a_day_of_week(date)
54-
assert day_of_week in [
55-
"Monday",
56-
"Tuesday",
57-
"Wednesday",
58-
"Thursday",
59-
"Friday",
60-
"Saturday",
61-
"Sunday",
62-
]
56+
day_of_week = dtu.get_day_of_week()
57+
assert day_of_week in VALID_WEEKDAYS

utils/date_time_utils.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime, timedelta
2+
from typing import Optional
23
import random
34

45

@@ -46,27 +47,18 @@ def add_days(date: datetime, days: float) -> datetime:
4647
return date + timedelta(days=days)
4748

4849
@staticmethod
49-
def get_day_of_week_for_today(date: datetime) -> str:
50-
"""Gets the day of the week (e.g., Monday, Tuesday) from the specified date.
51-
52-
Args:
53-
date (datetime): The current date using the now function
54-
55-
Returns:
56-
str: The day of the week relating to the specified date.
50+
def get_day_of_week(date: Optional[datetime] = None) -> str:
5751
"""
58-
return date.strftime("%A")
59-
60-
@staticmethod
61-
def get_a_day_of_week(date: datetime) -> str:
62-
"""Gets the day of the week (e.g., Monday, Tuesday) from the specified date.
52+
Returns the day of the week (e.g., Monday, Tuesday) for the given date.
53+
If no date is provided, uses today’s date.
6354
6455
Args:
65-
date (datetime): The date for which the day of the week will be returned.
56+
date (Optional[datetime]): The date to inspect. Defaults to now.
6657
6758
Returns:
68-
str: The day of the week relating to the specified date.
59+
str: Day of week corresponding to the date.
6960
"""
61+
date = date or datetime.now()
7062
return date.strftime("%A")
7163

7264
@staticmethod
@@ -99,7 +91,8 @@ def screening_practitioner_appointments_report_timestamp_date_format() -> str:
9991

10092
return DateTimeUtils.format_date(datetime.now(), "%d.%m.%Y at %H:%M:%S")
10193

102-
def month_string_to_number(self, string: str) -> int:
94+
@staticmethod
95+
def month_string_to_number(string: str) -> int:
10396
"""
10497
This is used to convert a month from a string to an integer.
10598
It accepts the full month or the short version and is not case sensitive
@@ -126,7 +119,8 @@ def month_string_to_number(self, string: str) -> int:
126119
except Exception:
127120
raise ValueError("Not a month")
128121

129-
def generate_unique_weekday_date(self, start_year: int = 2025) -> str:
122+
@staticmethod
123+
def generate_unique_weekday_date(start_year: int = 2025) -> str:
130124
"""
131125
Generates a future weekday date from the specified year onward.
132126

0 commit comments

Comments
 (0)