Skip to content

Commit 0d361db

Browse files
committed
Addressed sonaqube failures
1 parent a16f2d2 commit 0d361db

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

utils/date_time_utils.py

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44

55
class DateTimeUtils:
6+
UTC_TIMEZONE = "UTC"
7+
DST_TIMEZONE = "Europe/London"
68
"""
79
A utility class for doing common actions with datetimes.
810
"""
@@ -70,55 +72,63 @@ def get_a_day_of_week(date: datetime) -> str:
7072
return date.strftime("%A")
7173

7274
@staticmethod
73-
def report_timestamp_date_format() -> str:
74-
# If the bcss timestamp is displaying in UTC, set this to True
75-
# If the bcss timestamp is displaying in DST, set this to False
76-
USE_UTC = True
75+
def report_timestamp_date_format(use_utc: bool = True) -> str:
76+
"""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.
78+
"""
7779

7880
"""Gets the current datetime in the timestamp format used on the report pages.
7981
Based on the value of `USE_UTC`, it chooses the appropriate timezone.
8082
"""
81-
if USE_UTC:
83+
if use_utc:
8284
return DateTimeUtils.format_date(
83-
datetime.now(ZoneInfo("UTC")), "%d/%m/%Y at %H:%M:%S"
85+
datetime.now(ZoneInfo(DateTimeUtils.UTC_TIMEZONE)),
86+
"%d/%m/%Y at %H:%M:%S",
8487
)
8588
else:
8689
return DateTimeUtils.format_date(
87-
datetime.now(ZoneInfo("Europe/London")), "%d/%m/%Y at %H:%M:%S"
90+
datetime.now(ZoneInfo(DateTimeUtils.DST_TIMEZONE)),
91+
"%d/%m/%Y at %H:%M:%S",
8892
)
8993

9094
@staticmethod
91-
def fobt_kits_logged_but_not_read_report_timestamp_date_format() -> str:
92-
# If the bcss timestamp is displaying in UTC, set this to True
93-
# If the bcss timestamp is displaying in DST, set this to False
94-
USE_UTC = False
95+
def fobt_kits_logged_but_not_read_report_timestamp_date_format(
96+
use_utc: bool = False,
97+
) -> str:
98+
"""Gets the current datetime in the format used for FOBT Kits Logged but Not Read report.
99+
Based on the value of `use_utc`, it chooses the appropriate timezone.
100+
"""
95101

96102
"""Gets the current datetime in the format used for FOBT Kits Logged but Not Read report.
97103
Based on the value of `USE_UTC`, it chooses the appropriate timezone.
98104
"""
99-
if USE_UTC:
105+
if use_utc:
100106
return DateTimeUtils.format_date(
101-
datetime.now(ZoneInfo("UTC")), "%d %b %Y %H:%M:%S"
107+
datetime.now(ZoneInfo(DateTimeUtils.UTC_TIMEZONE)), "%d %b %Y %H:%M:%S"
102108
)
103109
else:
104110
return DateTimeUtils.format_date(
105-
datetime.now(ZoneInfo("Europe/London")), "%d %b %Y %H:%M:%S"
111+
datetime.now(ZoneInfo(DateTimeUtils.DST_TIMEZONE)), "%d %b %Y %H:%M:%S"
106112
)
107113

108114
@staticmethod
109-
def screening_practitioner_appointments_report_timestamp_date_format() -> str:
110-
# If the bcss timestamp is displaying in UTC, set this to True
111-
# If the bcss timestamp is displaying in DST, set this to False
112-
USE_UTC = True
115+
def screening_practitioner_appointments_report_timestamp_date_format(
116+
use_utc: bool = True,
117+
) -> str:
118+
"""Gets the current datetime in the format used for Screening Practitioner Appointments report.
119+
Based on the value of `use_utc`, it chooses the appropriate timezone.
120+
"""
113121

114122
"""Gets the current datetime in the format used for Screening Practitioner Appointments report.
115123
Based on the value of `USE_UTC`, it chooses the appropriate timezone.
116124
"""
117-
if USE_UTC:
125+
if use_utc:
118126
return DateTimeUtils.format_date(
119-
datetime.now(ZoneInfo("UTC")), "%d.%m.%Y at %H:%M:%S"
127+
datetime.now(ZoneInfo(DateTimeUtils.UTC_TIMEZONE)),
128+
"%d.%m.%Y at %H:%M:%S",
120129
)
121130
else:
122131
return DateTimeUtils.format_date(
123-
datetime.now(ZoneInfo("Europe/London")), "%d.%m.%Y at %H:%M:%S"
132+
datetime.now(ZoneInfo(DateTimeUtils.DST_TIMEZONE)),
133+
"%d.%m.%Y at %H:%M:%S",
124134
)

0 commit comments

Comments
 (0)