Skip to main content

Module time

Module time 

Source
Expand description

One strict grammar for every protocol time.

Credentials, status lists, receipts and every other signed object carry their times as strings. If two modules (or two languages) read the same string differently, a time one of them refuses can pass in another. So every protocol time in the core goes through this module, and the grammar is the same one the Python, TypeScript and Go implementations use (test-vectors/time/vector.json is the shared contract):

YYYY-MM-DDTHH:MM:SS[.fraction](Z | +HH:MM | -HH:MM)
  • T and Z are upper case and nothing else may appear in the string (no spaces, no trailing newline, no missing offset).
  • Years run 0001-9999, months and days are real calendar days, hours are 00-23, minutes and seconds 00-59 (a leap second :60 is refused).
  • The fraction has 1 to 9 digits and is kept at full precision: compare instants with parse_protocol_time_ns, never with whole seconds.
  • The offset is at most 23:59 either way, and the instant it names, moved to UTC, must still fall inside 0001-01-01T00:00:00Z .. 9999-12-31T23:59:59.999999999Z.

A now without a timezone does not match the grammar, so it is refused like any other malformed time. Clock skew is 0 to 120 seconds (check_clock_skew); anything else is refused.

Enums§

WindowState
Where now falls against a validity window.

Constants§

MAX_CLOCK_SKEW_SECONDS
The largest clock skew a verifier may allow, in seconds.

Functions§

check_clock_skew
Return the clock skew in nanoseconds when it is an allowed value (0 to MAX_CLOCK_SKEW_SECONDS seconds), else an error.
clock_skew_from_json
Read a clock skew from a JSON request: a whole number of seconds (an integral float such as 30.0 counts as 30) in 0 to MAX_CLOCK_SKEW_SECONDS. Booleans, strings, null, fractions and numbers outside the range are refused.
epoch_seconds_to_iso
Format whole seconds since the Unix epoch as YYYY-MM-DDTHH:MM:SSZ, the inverse of iso_to_epoch_seconds for whole-second UTC instants. The wrappers use it to turn the host clock into the now a verifier passes to the core.
iso_to_epoch_seconds
Parse a protocol time to whole Unix epoch seconds (the floor of the exact instant). Uses the strict grammar of parse_protocol_time_ns.
parse_protocol_time_ns
Parse a protocol time into exact nanoseconds since 1970-01-01T00:00:00Z (negative before 1970). Works on bytes and checks every position, so malformed or non-ASCII input returns an error and never panics.
seconds_to_ns
Seconds to nanoseconds, for comparing a whole-second bound (a max age, an interval) against parsed instants.
window_state
window_state_ns over protocol-time strings. Errors on a malformed time or an out-of-range skew.
window_state_ns
Place now_ns against [from - skew, until + skew] at full precision. A missing bound is open on that side. An inverted window is reported first.