data_updater_v2.data_clients.times
times.py — the time helpers the runner and RawResponse need, on the standard library.
Taken from nc-feeds, where the runner speaks the package’s own Time contract; here the
same moves are done with datetime alone. A walk speaks ONE unit end to end
(TimeUnit): a "date" value is a datetime.date; "datetime", "epoch" and
"epoch_ms" values are timezone-aware datetime.datetime. Arithmetic on instants is
done in UTC, so a shift is exact elapsed time whatever wall clock the vendor writes in.
parse a vendor's value, in the declared unit and zonerender back into the vendor's unit for a request parametershift_by forward or back by a spancoerce any date-like value, unit unknown (a ``RawResponse`` coverage edge)day the calendar day of a valueiso one ISO string, for messagesFunctions
coerce
coerce(value: Any) -> TimeValueA date-like value with no declared unit: a date or an instant as given, or ISO text —
a bare YYYY-MM-DD is a date, anything longer an instant (UTC when naive).
day
day(value: TimeValue) -> dt.dateThe calendar day of a value (an instant’s own wall-clock day).
iso
iso(value: TimeValue) -> strparse
parse(value: Any, unit: TimeUnit, zone: str | None = None) -> TimeValueA vendor’s time value in the declared unit: a date for "date", an aware instant
otherwise. Epoch units read numbers (and digit strings) as seconds or milliseconds.
render
render(value: TimeValue, unit: TimeUnit, zone: str | None = None) -> AnyA time value back into the vendor’s unit, for a request parameter.
shift_by
shift_by(value: TimeValue, unit: TimeUnit, delta: dt.timedelta) -> TimeValueForward or back by delta: calendar days for dates, exact elapsed time for instants.