Module epoch

Module epoch 

Source
Expand description

Conversion between broken-down civil time and the Unix epoch.

Receivers report the date and time of day as separate fields, and PROP_TIME carries one UINT32 second count, so something has to convert between them. Hosts need the same conversion in reverse to show an operator what the device thinks the time is.

The arithmetic is Howard Hinnant’s days-from-civil algorithm: integer only, no lookup tables, and correct for the whole proleptic Gregorian calendar rather than only for the years a leap-year table happens to cover.

Everything here is UTC. A local time-zone offset is presentation, applied by whatever is doing the presenting — see DateTime::shifted.

Structs§

DateTime
A broken-down civil date and time, in UTC unless a caller has deliberately shifted it.

Constants§

MAX_EPOCH
The largest second count u32 can express: 2106-02-07T06:28:15Z.
MIN_PLAUSIBLE_EPOCH
The earliest instant a receiver is believed: 2020-01-01T00:00:00Z.

Functions§

civil_from_days
The proleptic Gregorian date days after 1970-01-01. The inverse of days_from_civil.
days_from_civil
Days since 1970-01-01 for a proleptic Gregorian date.
days_in_month
Days in month of year, 1-indexed. Zero for an out-of-range month, which makes an invalid month fail the day check in DateTime::is_valid rather than needing its own branch.
is_leap_year
The proleptic Gregorian leap-year rule.