Skip to content

Commit 9f5c24d

Browse files
committed
Updated date time util following the fix of the utc/dst timestamp issue in the bcss test branch
1 parent 8b66849 commit 9f5c24d

File tree

1 file changed

+16
-42
lines changed

1 file changed

+16
-42
lines changed

utils/date_time_utils.py

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
from datetime import datetime, timedelta
2-
from zoneinfo import ZoneInfo
32

43

54
class DateTimeUtils:
6-
UTC_TIMEZONE = "UTC"
7-
DST_TIMEZONE = "Europe/London"
85
"""
96
A utility class for doing common actions with datetimes.
107
"""
@@ -72,54 +69,31 @@ def get_a_day_of_week(date: datetime) -> str:
7269
return date.strftime("%A")
7370

7471
@staticmethod
75-
def report_timestamp_date_format(use_utc: bool = True) -> str:
72+
def report_timestamp_date_format() -> str:
7673
"""Gets the current datetime in the timestamp format used on the report pages.
77-
Based on the value of `use_utc`, it chooses the appropriate timezone.
74+
Returns:
75+
str: The current date and time in the format 'dd/mm/yyyy at hh:mm:ss'.
76+
e.g. '24/01/2025 at 12:00:00'
7877
"""
7978

80-
if use_utc:
81-
return DateTimeUtils.format_date(
82-
datetime.now(ZoneInfo(DateTimeUtils.UTC_TIMEZONE)),
83-
"%d/%m/%Y at %H:%M:%S",
84-
)
85-
else:
86-
return DateTimeUtils.format_date(
87-
datetime.now(ZoneInfo(DateTimeUtils.DST_TIMEZONE)),
88-
"%d/%m/%Y at %H:%M:%S",
89-
)
79+
return DateTimeUtils.format_date(datetime.now(), "%d/%m/%Y at %H:%M:%S")
9080

9181
@staticmethod
92-
def fobt_kits_logged_but_not_read_report_timestamp_date_format(
93-
use_utc: bool = False,
94-
) -> str:
82+
def fobt_kits_logged_but_not_read_report_timestamp_date_format() -> str:
9583
"""Gets the current datetime in the format used for FOBT Kits Logged but Not Read report.
96-
Based on the value of `use_utc`, it chooses the appropriate timezone.
84+
Returns:
85+
str: The current date and time in the format 'dd MonthName yyyy hh:mm:ss'.
86+
e.g. '24 Jan 2025 12:00:00'
9787
"""
9888

99-
if use_utc:
100-
return DateTimeUtils.format_date(
101-
datetime.now(ZoneInfo(DateTimeUtils.UTC_TIMEZONE)), "%d %b %Y %H:%M:%S"
102-
)
103-
else:
104-
return DateTimeUtils.format_date(
105-
datetime.now(ZoneInfo(DateTimeUtils.DST_TIMEZONE)), "%d %b %Y %H:%M:%S"
106-
)
89+
return DateTimeUtils.format_date(datetime.now(), "%d %b %Y %H:%M:%S")
10790

10891
@staticmethod
109-
def screening_practitioner_appointments_report_timestamp_date_format(
110-
use_utc: bool = True,
111-
) -> str:
112-
"""Gets the current datetime in the format used for Screening Practitioner Appointments report.
113-
Based on the value of `use_utc`, it chooses the appropriate timezone.
92+
def screening_practitioner_appointments_report_timestamp_date_format() -> str:
93+
"""Gets the current datetime in the format used for the screening practitioner appointments report.
94+
Returns:
95+
str: the current datetime in the format 'dd.mm.yyyy at hh:mm:ss'
96+
e.g. '24.01.2025 at 12:00:00'
11497
"""
11598

116-
if use_utc:
117-
return DateTimeUtils.format_date(
118-
datetime.now(ZoneInfo(DateTimeUtils.UTC_TIMEZONE)),
119-
"%d.%m.%Y at %H:%M:%S",
120-
)
121-
else:
122-
return DateTimeUtils.format_date(
123-
datetime.now(ZoneInfo(DateTimeUtils.DST_TIMEZONE)),
124-
"%d.%m.%Y at %H:%M:%S",
125-
)
99+
return DateTimeUtils.format_date(datetime.now(), "%d.%m.%Y at %H:%M:%S")

0 commit comments

Comments
 (0)