@@ -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
0 commit comments