aeat.core.time._utc module¶
Canonical UTC datetime helpers.
Two semantics exist across the codebase for handling naive datetimes:
coerce_utc_aware()— coerce a naive datetime to UTC-aware by attachingUTC. Used where the source produces naive datetimes (e.g. PKCS#12 certificate timestamps).validate_utc_aware()— reject naive datetimes or non-UTC datetimes withCoreValidationError. Used at persistence and model boundaries where a naive datetime indicates a programming error.
parse_iso_datetime() is deliberately policy-neutral: it normalises the
Z suffix and returns the parsed datetime, leaving callers
to choose coerce_utc_aware() or validate_utc_aware().
- parse_iso_datetime(raw)[source]¶
Parse an ISO-8601 datetime string, normalising a trailing
Zto+00:00.datetime.fromisoformat()historically rejects theZUTC suffix; this normalises it first so UTC-suffixed timestamps parse. The result may be naive or aware depending on the input — pass it throughvalidate_utc_aware()orcoerce_utc_aware()when an aware value is required.
- coerce_utc_aware(value)[source]¶
Return a UTC-aware datetime, coercing a naive one if necessary.
Naive datetimes have
datetime.UTCattached. Timezone-aware datetimes whose offset differs from UTC are converted viadatetime.astimezone().
- validate_utc_aware(value)[source]¶
Return value unchanged if it is a UTC-aware datetime.
Raises
aeat.core.errors.CoreValidationErrorwhen value is naive (notzinfo) or when its UTC offset is not zero (i.e. not UTC).- Parameters:
value (
datetime) – The datetime to validate.- Return type:
- Returns:
value unchanged.
- Raises:
CoreValidationError – When value is naive or not in UTC.