Skip to content

Commit 4446d87

Browse files
committed
include recorded to also not be a future date
1 parent 7d9c772 commit 4446d87

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

backend/src/models/utils/pre_validator_utils.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ def for_date_time(field_value: str, field_location: str, strict_timezone: bool =
121121
"- 'YYYY-MM-DD' — Full date only"
122122
"- 'YYYY-MM-DDThh:mm:ss%z' — Full date and time with timezone (e.g. +00:00 or +01:00)"
123123
"- 'YYYY-MM-DDThh:mm:ss.f%z' — Full date and time with milliseconds and timezone"
124+
"Date must not be in the future."
124125
)
125126
if strict_timezone:
126127
error_message += (
127128
"Only '+00:00' and '+01:00' are accepted as valid timezone offsets.\n"
128129
f"Note that partial dates are not allowed for {field_location} in this service.\n"
129-
"Date must not be in the future."
130130
)
131131

132132
allowed_suffixes = {"+00:00", "+01:00", "+0000", "+0100",}
@@ -140,15 +140,13 @@ def for_date_time(field_value: str, field_location: str, strict_timezone: bool =
140140
for fmt in formats:
141141
try:
142142
fhir_date = datetime.strptime(field_value, fmt)
143+
# Enforce future-date rule using central checker (after successful parse)
144+
if PreValidation.check_if_future_date(fhir_date):
145+
raise ValueError(f"{field_location} must not be in the future")
143146
# After successful parse, enforce timezone and future-date rules
144147
if strict_timezone and fhir_date.tzinfo is not None:
145148
if not any(field_value.endswith(suffix) for suffix in allowed_suffixes):
146149
raise ValueError(error_message)
147-
148-
# Enforce not-in-the-future rule using central checker (after successful parse)
149-
if PreValidation.check_if_future_date(fhir_date):
150-
raise ValueError(f"{field_location} must not be in the future")
151-
152150
return fhir_date.isoformat()
153151
except ValueError:
154152
continue

backend/tests/utils/pre_validation_test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,13 @@ def test_date_time_value(
343343
"- 'YYYY-MM-DD' — Full date only"
344344
"- 'YYYY-MM-DDThh:mm:ss%z' — Full date and time with timezone (e.g. +00:00 or +01:00)"
345345
"- 'YYYY-MM-DDThh:mm:ss.f%z' — Full date and time with milliseconds and timezone"
346+
"Date must not be in the future."
346347
)
347348

348349
if is_occurrence_date_time:
349350
expected_error_message += (
350351
"Only '+00:00' and '+01:00' are accepted as valid timezone offsets.\n"
351352
f"Note that partial dates are not allowed for {field_location} in this service.\n"
352-
"Date must not be in the future."
353353
)
354354
valid_datetime_formats = ValidValues.for_date_times_strict_timezones
355355
invalid_datetime_formats = InvalidValues.for_date_time_string_formats_for_strict_timezone

0 commit comments

Comments
 (0)