Expand description
Date and datetime utilities.
EDTF level 0 (ISO 8601 subset used by DataCite and InvenioRDM) is the primary parser. A manual fallback handles malformed dates from upstream sources (e.g. single-digit months like “2023-8-25”).
Mirrors the Go dateutils package in front-matter/commonmeta.
Functions§
- date_
from_ parts - Build an ISO 8601 partial date from numeric parts.
Pass
0for month or day to omit that component.date_from_parts(2023, 8, 5)→"2023-08-05". - date_
from_ str_ parts - Build an ISO 8601 partial date from string parts (empty string = omit). Used for Crossref XML and RIS date fields.
- date_
only - Return only the date portion of a datetime string (first 10 characters).
"2024-01-15T12:34:56Z"→"2024-01-15". Pass-through for shorter strings. - normalize_
date - Pad single-digit month/day components to two digits so they are valid EDTF/ISO 8601.
"2023-8-5"→"2023-08-05","2023-8-5T12:00:00"→"2023-08-05T12:00:00". - parse_
date - Parse a date or datetime string and return an ISO 8601 date
(
"YYYY","YYYY-MM", or"YYYY-MM-DD"). Time components are discarded. - parse_
datetime - Parse a date or datetime string and return an ISO 8601 datetime
(
"YYYY-MM-DDTHH:MM:SSZ"), or a date-only string when the time is midnight. Returns""on failure. - sanitize_
date - Sanitize an arbitrary date string from upstream sources into valid EDTF / ISO 8601. Handles, in order:
- strip_
milliseconds - Remove sub-second fractions from an ISO 8601 datetime string.
A midnight time component (
T00:00:00) is stripped entirely, leaving only the date. Normalises+00:00timezone suffix toZ. - unix_
to_ date - Convert a Unix timestamp to an ISO 8601 date string (
"YYYY-MM-DD"). - unix_
to_ datetime - Convert a Unix timestamp to an ISO 8601 datetime string (
"YYYY-MM-DDTHH:MM:SSZ").