Skip to content

Commit 9aef06a

Browse files
authored
Merge pull request #358 from NHSDigital/notifications-simplify-now-with-timezone
Use `datetime.now(tz)` wherever possible
2 parents 6d0d878 + 31fb86c commit 9aef06a

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

manage_breast_screening/notifications/management/commands/create_appointments.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ def add_arguments(self, parser):
3131
parser.add_argument(
3232
"date_str",
3333
nargs="?",
34-
default=datetime.today()
35-
.replace(tzinfo=TZ_INFO)
36-
.strftime(DIR_NAME_DATE_FORMAT),
34+
default=datetime.now(tz=TZ_INFO).strftime(DIR_NAME_DATE_FORMAT),
3735
help="yyy-MM-dd formatted date reflecting the Azure storage directory",
3836
)
3937

manage_breast_screening/notifications/management/commands/send_message_batch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def handle(self, *args, **options):
4343

4444
message_batch = MessageBatch.objects.create(
4545
routing_plan_id=routing_plan_id,
46-
scheduled_at=datetime.today().replace(tzinfo=TZ_INFO),
46+
scheduled_at=datetime.now(tz=TZ_INFO),
4747
status=MessageBatchStatusChoices.SCHEDULED.value,
4848
)
4949

manage_breast_screening/notifications/tests/queries/test_aggregate_query.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@ def create_appointment_set(
3737
return appt
3838

3939
def test_query_aggregates_appointments_and_cascade_counts(self):
40+
now = datetime.now(tz=ZoneInfo("Europe/London"))
4041
clinic1 = ClinicFactory(code="BU001", bso_code="BSO1", name="BSU 1")
4142
clinic2 = ClinicFactory(code="BU002", bso_code="BSO2", name="BSU 2")
4243

43-
date1 = datetime.today() - timedelta(days=10)
44-
date1.replace(tzinfo=ZoneInfo("Europe/London"))
44+
date1 = now - timedelta(days=10)
4545
df1 = date1.strftime("%Y-%m-%d")
4646

47-
date2 = datetime.today() - timedelta(days=15)
48-
date2.replace(tzinfo=ZoneInfo("Europe/London"))
47+
date2 = now - timedelta(days=15)
4948
df2 = date2.strftime("%Y-%m-%d")
5049

5150
nhsapp_read = {"nhsapp": "read"}

0 commit comments

Comments
 (0)