W3C datetime normalization and formatting for sitemap dates.
A NaiveDateTime is treated as UTC, a DateTime or ISO 8601 string keeps its offset and a
Date is written as YYYY-MM-DD. Sub-second precision is dropped.
Summary
Types
@type t() :: DateTime.t() | Date.t()
Functions
Casts a value to a DateTime or Date.
Accepts DateTime, NaiveDateTime (as UTC), Date and ISO 8601 strings. nil stays nil.
Raises ArgumentError for anything else, including integers.
@spec w3c(DateTime.t() | NaiveDateTime.t() | Date.t()) :: String.t()
Formats a date in the W3C datetime format.
iex> SiteMaps.Date.w3c(~U[2026-03-01 10:00:00.123Z])
"2026-03-01T10:00:00+00:00"
iex> SiteMaps.Date.w3c(~N[2026-03-01 10:00:00])
"2026-03-01T10:00:00+00:00"
iex> SiteMaps.Date.w3c(~D[2026-03-01])
"2026-03-01"