nx_ts.nx
buildroot/runtime/nx_ts.nx
about
nx_ts.nx -- Unix epoch <-> calendar / ISO-8601 conversion.
nx_log writes timestamps as raw seconds-since-epoch. That's
machine-readable but not human-readable: you can't tell at a
glance whether a log line was 2 minutes ago or 2 weeks ago.
This module provides:
- epoch -> (year, month, day, hour, min, sec) calendar tuple
using the Howard Hinnant civil-from-days algorithm (no
lookup tables, no floating point, exact).
- calendar -> ISO-8601 string formatter ("2026-04-25T03:14:07Z")
Reference: Hinnant, "chrono-Compatible Low-Level Date Algorithms",
http://howardhinnant.github.io/date_algorithms.html
Pairs with nx_log + nx_strfmt. No timezone handling -- we always
emit UTC ('Z' suffix). TZ awareness can come later if anyone
actually needs it.
dependencies 1 imports · 0 importers
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 40 | struct NxTsCal |
consts
| 27 | const NX_MAGIC_719468: i64 = 719468 |
| 28 | const NX_MAGIC_146097: i64 = 146097 |
| 29 | const NX_MAGIC_146096: i64 = 146096 |
| 30 | const NX_MAGIC_1460: i64 = 1460 |
| 31 | const NX_MAGIC_36524: i64 = 36524 |
| 32 | const NX_MAGIC_3600: i64 = 3600 |
| 33 | const NX_MAGIC_9999: i64 = 9999 |
| 34 | const NX_MAGIC_1970: i64 = 1970 |
| 35 | const NX_MAGIC_1234567890: i64 = 1234567890 |
| 36 | const NX_MAGIC_2009: i64 = 2009 |
| 37 | const NX_MAGIC_951782400: i64 = 951782400 |
| 38 | const NX_MAGIC_2000: i64 = 2000 |
| 49 | const NX_TS_CAL_BYTES: i64 = 48 |
| 52 | const NX_TS_DAYS_PER_YEAR: i64 = 365 |
| 54 | const NX_TS_SECS_PER_DAY: i64 = 86400 |
functions
| 60 | func nx_ts_civil_from_days(z: i64, out: *NxTsCal) -> i64 called by 1: nx_ts_from_epoch |
| 82 | func nx_ts_from_epoch(epoch_secs: i64, out: *NxTsCal) -> i64 |
| 109 | func nx_ts_write2(buf: *u8, off: i64, v: i64) -> i64 called by 1: nx_ts_format_iso |
| 121 | func nx_ts_write4(buf: *u8, off: i64, v: i64) -> i64 called by 1: nx_ts_format_iso |
| 141 | func nx_ts_format_iso(epoch_secs: i64, buf: *u8) -> i64 |
| 171 | func main() -> i64 |