In development. It changes without notice.
Topic
Clock & Time Zone
The wall clock and how far it is trusted, what set it last, and the time zones with their daylight-saving rules.
The clock is read and set through one set of functions, over a clock chip (Clock Chip Back End) on the boards that have one and over the ESP32-S3's own clock on the others (kleidos::
The clock holds UTC. The owner picks a time zone from a table, and the rules for daylight saving in both hemispheres are computed here, with no zone database. The record of what set the clock last is for a screen to show and is never an input to a decision; whether a precise source still vouches for it is another record, which One-Time Codes reads.
Files | |
| file | src/ |
| The civil calendar in UTC: a date and time of day to and from a Unix epoch. | |
| file | src/ |
| NVS-persisted record of WHO set the clock last (display-only). | |
| file | src/ |
| User timezone + DST preference facade: persistence and local display time. | |
| file | src/ |
| The precise-sync record: implementation of precise_ | |
| file | src/ |
| Whether the wall clock still holds a time a precise source set. | |
| file | src/ |
Device-agnostic real-time-clock access (the rtc:: namespace). | |
| file | src/ |
The SoC clock backend of the rtc:: facade: its trust rule, wake math and clock seam. | |
| file | src/ |
| Pure, host-testable timezone + DST model with an in-house DST engine. | |
| file | src/ |
| Trust-gated wall clock → Unix epoch: the one read every consumer shares. | |
| file | src/ |
| Each zone's standard UTC offset as a row label ("UTC+01:00"). | |
Namespaces | |
| namespace | kleidos:: |
| The real-time clock behind one interface, a clock chip or the SoC's internal RTC, with how far its time can be trusted. | |
| namespace | kleidos:: |
| Persistence and labeling for the last clock-set source tag. | |
Functions | |
| DateTime | kleidos:: |
| Convert a Unix epoch (UTC seconds since 1970-01-01) to date + time. | |
| uint32_t | kleidos:: |
| Convert a UTC calendar date + time of day to a Unix epoch. | |
| uint8_t | kleidos:: |
| The selected zone index into kZones (clamped; 0 = UTC default). | |
| const TimeZone & | kleidos:: |
The selected TimeZone entry (shorthand for kZones[zoneIdx()]). | |
| bool | kleidos:: |
| Select a zone by table index: validate, persist, cache, re-export TZ. | |
| bool | kleidos:: |
| The DST option: honor the zone's DST rule (default ON). | |
| bool | kleidos:: |
| Set the DST option: persist, cache, re-export the TZ string in effect. | |
| const char * | kleidos:: |
| The POSIX TZ string currently in effect (DST-rule or fixed variant). | |
| void | kleidos:: |
| Boot hook: load the persisted preference and export TZ to libc. | |
| LocalDateTime | kleidos:: |
| Convert a UTC epoch to local date/time in the active zone. | |
| uint32_t | kleidos:: |
| Convert a local date/time in the active zone to a UTC epoch. | |
| bool | kleidos:: |
Whether DST is in effect at utcEpoch under the active preference. | |
| bool | kleidos:: |
| Trust-gated "local now": read the clock and convert in one step. | |
| void | kleidos:: |
| Drop the cached preference so the next call re-reads NVS (host tests). | |
| uint32_t | kleidos:: |
| The clock-write count, to read before a precise write. | |
| void | kleidos:: |
Mark the clock write made after generationBeforeWrite as precise. | |
| void | kleidos:: |
| Clear the record: the clock is about to be written. | |
| bool | kleidos:: |
| Whether the clock still holds a precise time. | |
| Status | kleidos:: |
| The record, for the console. | |
| void | kleidos:: |
| Debug only: mark the clock's current value as precise, writing nothing. | |
| void | kleidos:: |
| Debug only: make the clock read as if it had never been set. | |
| bool | kleidos:: |
| Whether debugForgetClock is in effect. | |
| void | kleidos:: |
| Clear debugForgetClock; called by every path that sets the clock. | |
| bool | kleidos:: |
| Debug only: make the battery-backed RTC report its time lost. | |
| ClockTrust | kleidos:: |
| Report the trust level of the clock this board is currently keeping. | |
| bool | kleidos:: |
| Check if a usable clock is available on this board. | |
| RtcTime | kleidos:: |
| Read current time from the RTC. | |
| void | kleidos:: |
| Write the time of day to this board's clock, RTC chip or SoC timer. | |
| RtcDate | kleidos:: |
| Read current date from the RTC. | |
| void | kleidos:: |
| Write the calendar date to this board's clock, RTC chip or SoC timer. | |
| void | kleidos:: |
| Set the RTC date and time as one combined instant (atomic facade write). | |
| void | kleidos:: |
| Read date and time as one coherent single-instant snapshot. | |
| bool | kleidos:: |
| Read the clock only when it meets a minimum trust level. | |
| bool | kleidos:: |
| Check whether the RTC still reports valid clock integrity. | |
| bool | kleidos:: |
| Program the alarm and arm the alarm interrupt. | |
| bool | kleidos:: |
| Read back the currently programmed alarm. | |
| bool | kleidos:: |
| Disarm the alarm interrupt and clear a pending alarm flag. | |
| bool | kleidos:: |
| Query whether the alarm has fired (AF flag set). | |
| bool | kleidos:: |
| Arm the countdown timer with a reload value and source frequency. | |
| bool | kleidos:: |
| Stop the countdown timer and clear its interrupt enable and flag. | |
| bool | kleidos:: |
| Configure the CLKOUT pin output frequency (or disable it). | |
| bool | kleidos:: |
| Query whether the countdown timer is currently armed. | |
| bool | kleidos:: |
| Read the current CLKOUT pin configuration. | |
| bool | kleidos:: |
| Report whether this board can wake from deep sleep on an RTC alarm. | |
| bool | kleidos:: |
| Program the alarm and arm a deep-sleep pin wake from the RTC INT line. | |
| TrustEvaluation | kleidos:: |
| Evaluate the running clock's trust and effective epoch. | |
| uint64_t | kleidos:: |
| Clamp a raw wake delay to [kleidos:: | |
| uint64_t | kleidos:: |
| Compute the clamped LP-timer wake delay from now to a target epoch. | |
| uint64_t | kleidos:: |
| Convert a countdown (source frequency, tick count) to microseconds. | |
| uint32_t | kleidos:: |
Next Unix epoch strictly after nowEpoch matching the enabled alarm fields (disabled fields are wildcards). | |
| void | kleidos:: |
| Set the SoC clock to an epoch. | |
| uint32_t | kleidos:: |
| The SoC clock's current Unix epoch. | |
| constexpr uint8_t | kleidos:: |
| Day of week for a proleptic-Gregorian date (0=Sun..6=Sat). | |
| constexpr uint8_t | kleidos:: |
Day-of-month of the week-th dow in month of year. | |
| constexpr int32_t | kleidos:: |
| Pack a (month, day, hour) triple into a monotonically comparable key. | |
| constexpr bool | kleidos:: |
| Whether DST is active for a zone at a given local date/time. | |
| constexpr int16_t | kleidos:: |
| Effective UTC offset (minutes) for a zone at a given local date/time. | |
| constexpr int16_t | kleidos:: |
| Effective UTC offset (minutes), DST rule always honored. | |
| constexpr uint32_t | kleidos:: |
Convert a local date/time in tz to a UTC Unix epoch. | |
| constexpr uint32_t | kleidos:: |
Convert a local date/time in tz to a UTC Unix epoch (DST honored). | |
| LocalDateTime | kleidos:: |
Convert a UTC Unix epoch to local date/time in tz. | |
| LocalDateTime | kleidos:: |
Convert a UTC Unix epoch to local date/time in tz (DST honored). | |
| bool | kleidos:: |
| Whether the zone's DST rule is in effect at a given UTC instant. | |
| WallClockEpoch | kleidos:: |
| Read the trust-gated wall clock as Unix epoch seconds. | |
| const char *const * | kleidos:: |
| The offset labels, one per zone of kZones, in its order. | |
Variables | |
| constexpr uint32_t | kleidos:: |
| The smallest Unix epoch a clock may hold and count as set. | |
| constexpr int64_t | kleidos:: |
| Seconds in a day. | |
| constexpr const char * | kleidos:: |
| NVS namespace holding the timezone preference (the shared device-pref pool). | |
| constexpr const char * | kleidos:: |
| NVS key: selected zone index into kZones (u8; unset ⇒ 0 = UTC). | |
| constexpr const char * | kleidos:: |
| NVS key: DST option (bool; unset ⇒ true = DST rules honored). | |
| constexpr uint32_t | kleidos:: |
| Worst slow-clock error through a light sleep the budget assumes, ppm. | |
| constexpr uint32_t | kleidos:: |
| constexpr uint64_t | kleidos:: |
| Microseconds in one millisecond. | |
| constexpr uint64_t | kleidos:: |
| Parts per million. | |
| constexpr uint64_t | kleidos:: |
| Light sleep since the mark that spends kDriftBudgetMs at kLightSleepDriftBoundPpm, microseconds (200 s). | |
| constexpr uint32_t | kleidos:: |
| How far, in seconds, the clock may step back before it is untrusted. | |
| constexpr auto | kleidos:: |
| Curated selectable timezones. Index 0 is UTC (the safe default). | |
| constexpr auto | kleidos:: |
| Number of entries in kZones. | |
Proleptic-Gregorian civil-calendar core | |
Howard Hinnant's branch-free days↔civil algorithm, in UTC: exact and time-zone-free. | |
| int64_t | kleidos:: |
| Days from 1970-01-01 (UTC) to the given proleptic-Gregorian date. | |
| void | kleidos:: |
| Inverse of daysFromCivil — split a day count into a date. | |
Enumeration Type Documentation
ClockSource #
ClockTrust #
Trust ranking of the running wall clock.
SECURITY: this enum ranks how much a consumer may rely on the clock the device is currently keeping, specifically its survival across a power cycle and its resistance to trivial tampering. Higher is stronger; the ordering is meaningful and comparable with the relational operators.
None— No clock is running (no RTC backend, or the running clock is unset / integrity-flagged). Time must not be trusted at all.Volatile— A software/internal clock that keeps time while powered but is lost on power-off and offers no tamper resistance. Backed— A battery-backed hardware RTC whose time survives power-off and is the only level suitable for security-relevant timing (e.g. brute-force lockout windows).
- Warning
Backedis the maximum by design: only a battery-backed hardware RTC survives power-off and resists tampering. Never introduce a trust level aboveBacked— nothing on these boards can honestly claim more.
RtcClockOut #
RtcTimerSource #
Function Documentation
alarmNextEpoch() #
Next Unix epoch strictly after nowEpoch matching the enabled alarm fields (disabled fields are wildcards).
Hour/minute default to 0 when their field is a wildcard; day-of-month and weekday are matched via a bounded forward day scan.
- Parameters
-
Name Direction Meaning nowEpoch in Current epoch (seconds). alarm in Alarm match specification.
- Returns
- The next matching epoch, or 0 when no match falls inside the scan window.
alarmTriggered() #
Query whether the alarm has fired (AF flag set).
- Returns
- True when the alarm flag is set; false when it is clear, on bus error, or when no RTC backend is available.
applyEpochToClock() #
Set the SoC clock to an epoch.
On the device it writes the SoC RTC through settimeofday. Defined in the !HAS_ backend translation unit (rtc_). It is a seam rather than a direct call because the same translation unit is compiled for the host, where that syscall sets the clock of the machine running the tests rather than a SoC peripheral.
A host build defines it inline instead and records the epoch in memory, since settimeofday there is the machine's own clock, a global side effect that has repeatedly moved the clock of the machine running the suite. The seed-floor cache, the NVS write and the generation bump are then exercised exactly as on the device with nothing outside the process observing it.
- Parameters
-
Name Direction Meaning epoch in Unix epoch to apply to the SoC RTC (on a host build, to record in memory).
applyFromStorage() #
Boot hook: load the persisted preference and export TZ to libc.
Call once early in setup() (after NVS is usable, before any time display). Conversions would lazy-load anyway; this makes the libc TZ export deterministic from the first frame.
armAlarmWake() #
Program the alarm and arm a deep-sleep pin wake from the RTC INT line.
Writes the alarm via setAlarm, then configures the SoC to wake from deep sleep when the RTC asserts its INT line. The BM8563/enablePinWakeup with wakeOnHigh == false). Only functional on boards where rtcAlarmWakeSupported returns true; elsewhere it writes nothing, not even the alarm, and returns false.
- Note
- The alarm arrives as a pin wake, so
kleidos::reportsplatform:: sleep:: wakeCause() WakeCause::orExt0 WakeCause::(whicheverGpio enablePinWakeupselected) — notWakeCause::.Timer WakeCause::denotes the ESP32's own internal RTC timer, an unrelated source; there is no dedicated RTC-alarm wake cause.Timer
- Parameters
-
Name Direction Meaning alarm in Alarm match specification (disabled fields are wildcards).
- Return values
-
Value Meaning true Alarm programmed and the pin wake source armed. false Unsupported board, or the alarm write / wake config failed.
civilFromDays() #
Inverse of daysFromCivil — split a day count into a date.
- Parameters
-
Name Direction Meaning days in Signed day count relative to the Unix epoch day. yearOut out Receives the full year. monthOut out Receives the month, 1..12. dayOut out Receives the day of month, 1..31.
clampWakeMicros() #
Clamp a raw wake delay to [kleidos::
- Parameters
-
Name Direction Meaning micros in Raw wake delay in microseconds.
- Returns
- The clamped wake delay in microseconds.
clearAlarm() #
Disarm the alarm interrupt and clear a pending alarm flag.
- Returns
- True on success; false on bus error or when no RTC backend is available.
clockIntegrityValid() #
Check whether the RTC still reports valid clock integrity.
The VL (voltage-low) flag latches on power loss; when it is set the calendar contents are unreliable until the clock is re-set.
- Returns
- True when the clock integrity is intact; false when VL is set or no RTC backend is available.
clockTrust() #
Report the trust level of the clock this board is currently keeping.
SECURITY: consumers gate security-relevant timing decisions on this value. Only a present, integrity-valid, battery-backed hardware RTC returns ClockTrust::; a volatile internal clock returns ClockTrust::; an absent or unset/invalid clock returns ClockTrust::. The SoC clock backend decides it by kleidos::
- Returns
- The current ClockTrust of the active backend.
computeWakeMicros() #
Compute the clamped LP-timer wake delay from now to a target epoch.
A target at or before now arms the minimum wake — never 0 / underflow.
- Parameters
-
Name Direction Meaning nowEpoch in Current epoch (seconds). targetEpoch in Target wake epoch (seconds).
- Returns
- The clamped wake delay in microseconds.
configureClockOut() #
Configure the CLKOUT pin output frequency (or disable it).
- Parameters
-
Name Direction Meaning freq in Desired CLKOUT frequency, or RtcClockOut:: Off to disable.
- Returns
- True on success; false on bus error or when no RTC backend is available.
countdownToMicros() #
Convert a countdown (source frequency, tick count) to microseconds.
- Parameters
-
Name Direction Meaning src in Countdown source frequency. ticks in Reload value at the source rate; 0 disables (maps to 0).
- Returns
- The countdown duration in microseconds (0 when
ticksis 0).
currentEpoch() #
The SoC clock's current Unix epoch.
On the device it reads the SoC RTC through gettimeofday. Defined in the !HAS_ backend translation unit (rtc_). A host build defines it inline instead: the epoch an installed test epoch source returns, else the last one applyEpochToClock recorded in memory.
- Returns
- The current Unix epoch (seconds, UTC) from the SoC RTC; on a host build the injected epoch, the last applied one, or 0 when neither exists.
dateTimeToEpoch() #
Convert a UTC calendar date + time of day to a Unix epoch.
- Parameters
-
Name Direction Meaning date in Calendar date (UTC). time in Time of day (UTC).
- Returns
- Seconds since the Unix epoch (UTC).
daysFromCivil() #
Days from 1970-01-01 (UTC) to the given proleptic-Gregorian date.
- Parameters
-
Name Direction Meaning year in Full year (e.g. 2026); may be negative (proleptic). month in Month, 1..12. day in Day of month, 1..31.
- Returns
- Signed day count relative to the Unix epoch day (negative before it).
debugClockForgotten() #
Whether debugForgetClock is in effect.
- Returns
- True while the clock is being reported as never set.
debugForgetClock() #
Debug only: make the clock read as if it had never been set.
A board with a battery-backed RTC cannot be talked out of knowing the time, and a test cannot wait for its cell to die, but several screens exist only for a device whose clock is not set (the TOTP page's empty state, the lock face without its clock, setup's clock step). This latch lets a console reach them: while it is set, clockTrust reports None on every backend, and the next time the clock is set it clears itself.
SECURITY: this only ever lowers trust, so a lockout window can never be shortened by it: the lockout fails closed on an untrusted clock. Compiled only into debug builds, never into a production image.
debugMarkClockLost() #
Debug only: make the battery-backed RTC report its time lost.
Unlike debugForgetClock, which a reboot forgets, this raises the RTC chip's own integrity flag, as a drained cell does, so every later boot reads the clock as untrusted until the clock is set. The bench's way to reach a lock armed on a battery-backed clock that then lost it.
SECURITY: it only ever lowers trust. Compiled only into debug builds.
- Return values
-
Value Meaning true The flag was raised (a board with a battery-backed RTC chip). false No such chip, or the write failed.
debugMarkSynced() #
Debug only: mark the clock's current value as precise, writing nothing.
The console's stand-in for a precise sync, so a test can set a fixed instant (which clears the record) and still reach the screens a code needs.
dowOfCivil() #
Day of week for a proleptic-Gregorian date (0=Sun..6=Sat).
Reuses the calendar core in calendar.h — the WS-A weekday expression (daysFromCivil+4)%7 with the C++ remainder made non-negative.
- Parameters
-
Name Direction Meaning y in Full year (e.g. 2026). m in Month, 1..12. d in Day of month, 1..31.
- Returns
- Day of week, 0=Sunday .. 6=Saturday.
dstActiveAt() #
Whether DST is in effect at utcEpoch under the active preference.
- Parameters
-
Name Direction Meaning utcEpoch in UTC Unix epoch (seconds since 1970-01-01).
- Returns
- True only when the DST option is on and the zone's rule is active.
dstEnabled() #
The DST option: honor the zone's DST rule (default ON).
- Returns
- True when conversions apply the zone's DST rule.
effectiveOffsetMin() [1/2] #
Effective UTC offset (minutes), DST rule always honored.
- Parameters
-
Name Direction Meaning tz in The timezone. date in Local calendar date. time in Local time of day.
- Returns
- Standard offset plus the DST offset when DST is active.
effectiveOffsetMin() [2/2] #
Effective UTC offset (minutes) for a zone at a given local date/time.
dstEnabled is the user's DST option (default ON): when false the zone behaves as its fixed standard offset and the rule is never evaluated.
- Parameters
-
Name Direction Meaning tz in The timezone. date in Local calendar date. time in Local time of day. dstEnabled in Honor the zone's DST rule (false ⇒ fixed offset).
- Returns
- Standard offset plus the DST offset when DST is enabled and active.
epochToDateTime() #
Convert a Unix epoch (UTC seconds since 1970-01-01) to date + time.
- Parameters
-
Name Direction Meaning unixEpoch in Seconds since the Unix epoch (UTC).
- Returns
- The calendar date and time of day.
evaluateTrust() #
Evaluate the running clock's trust and effective epoch.
SECURITY: this is the SoC clock's equivalent of the BM8563 voltage-low flag. A never-set clock, a cold start (power-on reset), or a backward jump beyond the drift margin (time tamper) all yield None; the lockout (Task 3) fails closed on anything below Backed. A seeded, clean-booted, forward/equal clock is Volatile. The returned effectiveEpoch is floored up to the last known floor so a caller that opts to use it never sees wall-clock time run backward; it is a convenience output only — the wired rtc::getTime / rtc::getDate return the raw reading and do not apply this floor, and no security decision depends on it (the lockout uses a separate monotonic source, not this wall clock).
- Parameters
-
Name Direction Meaning floorEpoch in Persisted NVS floor (last known good epoch), 0 if none. derivedNow in RTC-derived current epoch. coldBoot in True on a power-on reset with no fresh set this session. wasEverSet in True once the clock has ever been seeded/set.
- Returns
- The clock trust and the monotonic-floored effective epoch.
fresh() #
Whether the clock still holds a precise time.
- Return values
-
Value Meaning true A precise write was marked this boot, no clock write followed, and the light sleep since is within kLightSleepBudgetMicros. false Otherwise.
getDate() #
Read current date from the RTC.
- Returns
- Current calendar date from the hardware clock.
getDateTime() #
Read date and time as one coherent single-instant snapshot.
Unlike a getDate + getTime pair — two independent backend reads that can straddle a second/gettimeofday, and the BM8563 backend reads all seven time/date registers in one I2C burst (the PCF8563-class chip latches the counters for the duration of a sequential read).
On a backend read failure both outputs are zero-filled (matching the getTime / getDate failure behavior).
- Parameters
-
Name Direction Meaning date out Receives the calendar date (UTC). time out Receives the time of day (UTC).
getTime() #
Read current time from the RTC.
- Returns
- Current time-of-day from the hardware clock.
getValidTime() #
Read the clock only when it meets a minimum trust level.
SECURITY: a single trust gate for consumers that must not act on an untrustworthy clock. The output is filled and true returned only when the running clock is present and at least as trusted as minTrust, i.e. clockTrust() != None and clockTrust() >= minTrust. A board with clockTrust() == None therefore never yields a valid time, regardless of minTrust. On failure date and time are left untouched.
Backend-agnostic by construction: it derives its answer purely from clockTrust and getDateTime, so both the hardware and the fallback backends share this one definition. The read goes through getDateTime, so on success date and time are guaranteed to describe the same instant — they can never straddle a second/getDate() + getTime() pair could.
- Parameters
-
Name Direction Meaning date out Receives the calendar date on success; untouched on failure. time out Receives the time of day on success; untouched on failure. minTrust in Minimum trust the running clock must meet.
- Return values
-
Value Meaning true The clock met minTrust;dateandtimewere filled.false The clock was absent or below minTrust; outputs untouched.
invalidate() #
Clear the record: the clock is about to be written.
Every clock write calls this first, before the clock moves, in both rtc:: backends. Also the console's way to drop a sync.
isAvailable() #
Check if a usable clock is available on this board.
Shim over clockTrust — a clock is available when the running clock is anything other than ClockTrust::. Callers that need to distinguish a power-off-surviving hardware clock from a volatile one must inspect clockTrust directly.
- Return values
-
Value Meaning true clockTrust returns VolatileorBacked.false clockTrust returns None(no/absent/ unset clock).
isDstActive() #
Whether DST is active for a zone at a given local date/time.
Resolves the rule from the entered local instant alone: builds the concrete start/end days for date's year, forms comparable (month, day, hour) keys, and compares. Northern rules (start month < end month) are active on start <= now < end; southern rules (start month > end month, DST wraps the new year) are active on now >= start || now < end.
- Local-anchored transition approximation (deliberate)
- The rule hours are compared against the local wall clock on both sides of a transition, while real-world rules may anchor elsewhere (the EU rule fires at 01:00 UTC, i.e. at a different wall hour in each member zone). Within the one-hour window around each of the two yearly transitions this engine can therefore flip up to 1–2 hours away from the legal instant; everywhere else in the year it is exact. The trade is deliberate: the decision needs no UTC pre-pass and stays self-consistent in both conversion directions (localToUtcEpoch / utcEpochToLocal).
Inside the window the behavior is a plain half-open key comparison, pinned by the host tests: a local instant at/after the rule hour takes the post-transition offset. A local time in the spring-forward gap (the skipped wall hour) therefore resolves via the DST offset, and a fall-back ambiguous time (the repeated wall hour) resolves via the standard offset — i.e. its second, post-transition occurrence.
- Parameters
-
Name Direction Meaning tz in The timezone (its dstrule drives the decision).date in Local calendar date. time in Local time of day.
- Returns
- True when DST is in effect at that local instant.
isDstActiveAtUtc() #
Whether the zone's DST rule is in effect at a given UTC instant.
Resolves the rule against the standard-offset-shifted local instant (the same first pass utcEpochToLocal uses), so the answer is consistent with the conversion functions. Approximate within the one-hour transition window like the rest of the engine.
- Parameters
-
Name Direction Meaning utcEpoch in UTC Unix epoch (seconds since 1970-01-01). tz in The timezone whose rule is evaluated.
- Returns
- True when DST is in effect at that instant.
localNow() #
Trust-gated "local now": read the clock and convert in one step.
Reads the RTC through rtc::minTrust (the RTC stores UTC) and converts to the active zone. On failure out is untouched.
- Parameters
-
Name Direction Meaning out out Receives the local date/time on success. minTrust in Minimum trust the running clock must meet.
- Return values
-
Value Meaning true The clock met minTrust;outholds local time.false The clock was absent or below minTrust.
localToUtcEpoch() [1/2] #
Convert a local date/time in tz to a UTC Unix epoch (DST honored).
- Parameters
-
Name Direction Meaning date in Local calendar date. time in Local time of day. tz in The timezone the local instant is expressed in.
- Returns
- The corresponding UTC Unix epoch (seconds since 1970-01-01).
localToUtcEpoch() [2/2] #
Convert a local date/time in tz to a UTC Unix epoch.
dateTimeToEpoch treats its fields as UTC; subtracting the (DST-aware, possibly negative) local→UTC offset yields the true UTC epoch. Signed math is used throughout; the result is returned as a uint32_t epoch.
- Parameters
-
Name Direction Meaning date in Local calendar date. time in Local time of day. tz in The timezone the local instant is expressed in. dstEnabled in Honor the zone's DST rule (false ⇒ fixed offset).
- Returns
- The corresponding UTC Unix epoch (seconds since 1970-01-01).
markSynced() #
Mark the clock write made after generationBeforeWrite as precise.
Call right after the clock write, with what writeGeneration returned just before it. The mark holds while that write stays the last one: a write that raced it, or any later one, leaves the record clear.
- Parameters
-
Name Meaning generationBeforeWrite writeGeneration read before the write.
nthWeekdayDom() #
Day-of-month of the week-th dow in month of year.
- Parameters
-
Name Direction Meaning year in Full year (e.g. 2026). month in Month, 1..12. week in Ordinal week, 1..4, or 5 for "last". dow in Target weekday, 0=Sun..6=Sat.
- Returns
- The matching day of month, 1..31.
posixTz() #
readAlarm() #
Read back the currently programmed alarm.
- Parameters
-
Name Direction Meaning alarm out Receives the decoded alarm on success.
- Returns
- True on success; false on bus error or when no RTC backend is available.
readClockOut() #
Read the current CLKOUT pin configuration.
- Parameters
-
Name Direction Meaning freq out Receives the decoded CLKOUT frequency (Off when disabled).
- Returns
- True on success; false on bus error or when no RTC backend is available.
readCountdownTimerRunning() #
Query whether the countdown timer is currently armed.
- Parameters
-
Name Direction Meaning running out Set true when the timer-enable (TE) bit is set.
- Returns
- True on success; false on bus error or when no RTC backend is available.
rtcAlarmWakeSupported() #
Report whether this board can wake from deep sleep on an RTC alarm.
True only where the variant names the GPIO that reads the RTC INT line (RTC_INT_PIN), a real RTC backend is present (HAS_) and that GPIO can wake a deep sleep (sleep::). The CoreInk names GPIO19, which is no RTC GPIO, so it answers false there too. On a variant with no RTC_INT_PIN this is false and no pin is referenced.
- Return values
-
Value Meaning true armAlarmWake can arm a deep-sleep wake on this board. false No GPIO that can wake a deep sleep reads RTC INT here; armAlarmWake refuses.
setAlarm() #
Program the alarm and arm the alarm interrupt.
- Parameters
-
Name Direction Meaning alarm in Alarm match specification (disabled fields are wildcards).
- Returns
- True when the alarm was written and armed; false on bus error or when no RTC backend is available.
setCountdownTimer() #
Arm the countdown timer with a reload value and source frequency.
- Parameters
-
Name Direction Meaning src in Countdown source frequency. ticks in Reload value decremented at the source rate (0 disables).
- Returns
- True when the timer was programmed and armed; false on bus error or when no RTC backend is available.
setDate() #
Write the calendar date to this board's clock, RTC chip or SoC timer.
Clears the precise-sync record first (precise_
- Parameters
-
Name Direction Meaning d in Date value to write to the hardware clock.
setDateTime() #
Set the RTC date and time as one combined instant (atomic facade write).
Preferred over a setDate + setTime pair when both halves of an instant are known: the backend applies the combined instant in a single operation, so the write can never be observed half-applied and the cost is paid once. On the internal-RTC backend this is one settimeofday + one NVS floor write (a setDate + setTime pair pays two of each); on the BM8563 backend it is one sequential I2C burst over all seven time/date registers (the PCF8563-class register file supports a single auto-incrementing write from the seconds register).
- Parameters
-
Name Direction Meaning d in Date value to write to the hardware clock (UTC). t in Time value to write to the hardware clock (UTC).
setDstEnabled() #
Set the DST option: persist, cache, re-export the TZ string in effect.
- Parameters
-
Name Direction Meaning enabled in True to honor DST rules; false for fixed standard offsets.
- Return values
-
Value Meaning true The option is active and stored. false It is active in RAM only and reverts at the next boot.
setTime() #
Write the time of day to this board's clock, RTC chip or SoC timer.
Clears the precise-sync record first (precise_
- Parameters
-
Name Direction Meaning t in Time value to write to the hardware clock.
setZoneIdx() #
Select a zone by table index: validate, persist, cache, re-export TZ.
- Parameters
-
Name Direction Meaning idx in Index into kZones.
- Return values
-
Value Meaning true The index was valid and the preference is active and stored. false idx>= kZoneCount (nothing changed), or the zone is active in RAM but was not stored — the clock reads right now and reverts at the next boot, which a surface must not report as saved.
status() #
The record, for the console.
- Returns
- A snapshot; the figures since the mark are 0 while
everMarkedis false.
stopCountdownTimer() #
Stop the countdown timer and clear its interrupt enable and flag.
- Returns
- True on success; false on bus error or when no RTC backend is available.
toLocal() #
Convert a UTC epoch to local date/time in the active zone.
Honors the DST option (dstEnabled). Display-only — never feed the result back into epoch math.
- Parameters
-
Name Direction Meaning utcEpoch in UTC Unix epoch (seconds since 1970-01-01).
- Returns
- The local calendar date and time of day.
toUtc() #
Convert a local date/time in the active zone to a UTC epoch.
Honors the DST option (dstEnabled). The inverse edit-boundary conversion for screens where the user types local wall time.
- Parameters
-
Name Direction Meaning date in Local calendar date. time in Local time of day.
- Returns
- The corresponding UTC Unix epoch (seconds since 1970-01-01).
transitionKey() #
Pack a (month, day, hour) triple into a monotonically comparable key.
- Parameters
-
Name Direction Meaning month in Month, 1..12. day in Day of month, 1..31. hour in Hour of day, 0..23.
- Returns
- A single integer that orders instants within a year.
utcEpochToLocal() [1/2] #
Convert a UTC Unix epoch to local date/time in tz (DST honored).
- Parameters
-
Name Direction Meaning utcEpoch in UTC Unix epoch (seconds since 1970-01-01). tz in The target timezone.
- Returns
- The local calendar date and time of day.
utcEpochToLocal() [2/2] #
Convert a UTC Unix epoch to local date/time in tz.
The effective offset itself depends on the local instant near a transition, so the offset is first computed from the standard-offset-shifted instant and then applied. One iteration is sufficient for civil use; results within the one-hour transition window are approximate.
- Parameters
-
Name Direction Meaning utcEpoch in UTC Unix epoch (seconds since 1970-01-01). tz in The target timezone. dstEnabled in Honor the zone's DST rule (false ⇒ fixed offset).
- Returns
- The local calendar date and time of day.
wallClockEpoch() #
Read the trust-gated wall clock as Unix epoch seconds.
Reads the clock once via rtc::minTrust and, on success, converts the UTC calendar reading to Unix epoch seconds via calendar::minTrust) the conversion is skipped.
- Parameters
-
Name Direction Meaning minTrust in Minimum trust the running clock must meet.
- Returns
{epoch, true} when the clock metminTrust;{0, false} otherwise — the caller must not persist a stamp on afalseresult.
writeGeneration() #
The clock-write count, to read before a precise write.
Every clock write bumps it (invalidate). A precise writer reads it just before its own write and hands it to markSynced after.
- Returns
- The count of clock writes this boot.
zone() #
zoneIdx() #
The selected zone index into kZones (clamped; 0 = UTC default).
- Returns
- The cached (lazily NVS-loaded) zone index, always < kZoneCount.
zoneOffsetLabels() #
The offset labels, one per zone of kZones, in its order.
- Returns
- kZoneCount pointers to "UTC+HH:MM" strings; valid for the program's lifetime.
Variable Documentation
kBackwardJumpMarginSec #
How far, in seconds, the clock may step back before it is untrusted.
A lower "now" within this margin is benign RC-oscillator drift on a clean wake; a larger step back is treated as time tamper.
kDriftBudgetMs #
How far the clock may move from the precise time before it no longer counts as precise, milliseconds.
kLightSleepDriftBoundPpm #
Worst slow-clock error through a light sleep the budget assumes, ppm.
Measured on the three boards without an RTC chip, on the RC_FAST/256 slow clock with ESP-IDF's own calibration: -6033 to +2300 ppm over 66 sleeps of 1 minute to 3 hours (deep sleeps, light sleeps with the crystal off and on, sleeps right after a 10-minute load at 240 MHz), the sign shifting with the crystal and the die temperature. The bound rounds the worst case up, with room for temperature.
kMinValidEpoch #
The smallest Unix epoch a clock may hold and count as set.
2001-09-09T01:46:40Z, the smallest valid persisted seed. It matches the admin portal's set-time request check (epoch >= 1e9), so a zero/garbage NVS value never counts as "clock was set".
kZones #
Curated selectable timezones. Index 0 is UTC (the safe default).
- Warning
- APPEND-ONLY: the selected zone persists in NVS as an index into this table, so entries must never be reordered or removed — new zones go at the end. Every UTC whole-hour offset from -12 to +14 is covered by at least one entry.