|
1 | | -from datetime import datetime, timedelta |
2 | | -import pytz |
| 1 | +from datetime import datetime, timedelta, tzinfo |
| 2 | +from zoneinfo import ZoneInfo |
3 | 3 |
|
4 | 4 |
|
5 | 5 | class DateTimeUtils: |
@@ -71,27 +71,54 @@ def get_a_day_of_week(date: datetime) -> str: |
71 | 71 |
|
72 | 72 | @staticmethod |
73 | 73 | def report_timestamp_date_format() -> str: |
74 | | - """Gets the current datetime in the timestamp format used on the report pages.""" |
75 | | - # Use this option if bcss is displaying correct DST times |
76 | | - # return DateTimeUtils.format_date(datetime.now(), "%d/%m/%Y at %H:%M:%S") |
| 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 |
77 | 77 |
|
78 | | - # Use this option if bcss is displaying UTC times |
79 | | - return DateTimeUtils.format_date(datetime.now(pytz.utc), "%d/%m/%Y at %H:%M:%S") |
| 78 | + """Gets the current datetime in the timestamp format used on the report pages. |
| 79 | + Based on the value of `USE_UTC`, it chooses the appropriate timezone. |
| 80 | + """ |
| 81 | + if USE_UTC: |
| 82 | + return DateTimeUtils.format_date( |
| 83 | + datetime.now(ZoneInfo("UTC")), "%d/%m/%Y at %H:%M:%S" |
| 84 | + ) |
| 85 | + else: |
| 86 | + return DateTimeUtils.format_date( |
| 87 | + datetime.now(ZoneInfo("Europe/London")), "%d/%m/%Y at %H:%M:%S" |
| 88 | + ) |
80 | 89 |
|
81 | 90 | @staticmethod |
82 | 91 | def fobt_kits_logged_but_not_read_report_timestamp_date_format() -> str: |
83 | | - """Gets the current datetime in the format used for FOBT Kits Logged but Not Read report.""" |
84 | | - # Use this option if bcss is displaying correct DST times |
85 | | - return DateTimeUtils.format_date(datetime.now(), "%d %b %Y %H:%M:%S") |
| 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 |
86 | 95 |
|
87 | | - # Use this option if bcss is displaying UTC times |
88 | | - # return DateTimeUtils.format_date(datetime.now(pytz.utc), "%d %b %Y %H:%M:%S") |
| 96 | + """Gets the current datetime in the format used for FOBT Kits Logged but Not Read report. |
| 97 | + Based on the value of `USE_UTC`, it chooses the appropriate timezone. |
| 98 | + """ |
| 99 | + if USE_UTC: |
| 100 | + return DateTimeUtils.format_date( |
| 101 | + datetime.now(ZoneInfo("UTC")), "%d %b %Y %H:%M:%S" |
| 102 | + ) |
| 103 | + else: |
| 104 | + return DateTimeUtils.format_date( |
| 105 | + datetime.now(ZoneInfo("Europe/London")), "%d %b %Y %H:%M:%S" |
| 106 | + ) |
89 | 107 |
|
90 | 108 | @staticmethod |
91 | 109 | def screening_practitioner_appointments_report_timestamp_date_format() -> str: |
92 | | - """Gets the current datetime in the format used for Screening Practitioner Appointments report.""" |
93 | | - # Use this option if bcss is displaying correct DST times |
94 | | - # return DateTimeUtils.format_date(datetime.now(), "%d.%m.%Y at %H:%M:%S") |
| 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 |
95 | 113 |
|
96 | | - # Use this option if bcss is displaying UTC times |
97 | | - return DateTimeUtils.format_date(datetime.now(pytz.utc), "%d.%m.%Y at %H:%M:%S") |
| 114 | + """Gets the current datetime in the format used for Screening Practitioner Appointments report. |
| 115 | + Based on the value of `USE_UTC`, it chooses the appropriate timezone. |
| 116 | + """ |
| 117 | + if USE_UTC: |
| 118 | + return DateTimeUtils.format_date( |
| 119 | + datetime.now(ZoneInfo("UTC")), "%d.%m.%Y at %H:%M:%S" |
| 120 | + ) |
| 121 | + else: |
| 122 | + return DateTimeUtils.format_date( |
| 123 | + datetime.now(ZoneInfo("Europe/London")), "%d.%m.%Y at %H:%M:%S" |
| 124 | + ) |
0 commit comments