normalize_isodatetime#
- safir.pydantic.normalize_isodatetime(v)#
Pydantic validator for datetime fields in ISO format.
This validator requires the ISO 8601 date and time format with
Z
as the time zone (YYYY-MM-DDTHH:MM:SSZ
). This format is compatible with Kubernetes and the ISO UWS standard and is the same format produced bysafir.datetime.isodatetime
. It should be used when the ambiguous formats supported by Pydantic by default (such as dates and times without time zone information) shouldn’t be allowed.- Parameters:
- Returns:
- Return type:
datetime.datetime or None
Examples
Here is a partial model that uses this function as a validator.
class Info(BaseModel): last_used: Optional[datetime] = Field( None, title="Last used", description="Date and time last used", example="2023-01-25T15:44:34Z", ) _normalize_last_used = validator( "last_used", allow_reuse=True, pre=True )(normalize_isodatetime)