/* * tz.h - IANA timezone resolution for plugin_time. * * The connector cannot read the host's tz database: a Windows node has none, * macOS's is case-insensitive, and a slim container may have a different tzdata * version, all of which would make the same tool call answer differently per * node. So the table is embedded (src/tzdata.h, generated by * tools/gen_tzdata.py) and every platform resolves identically: * * tz_find() exact, case-sensitive IANA key -> zone record (or NULL) * tz_offset() UTC instant -> offset east of UTC, DST flag, abbreviation * tz_resolve_wall() a wall-clock local time -> the UTC instants it can mean * (two of them on a DST fall-back, none in a spring gap) * tz_local_name() the node's own timezone name, best effort * * Times are int64 seconds since the Unix epoch; nothing here reads the system * clock, so every function is deterministic and testable. * * MIT License. Copyright (c) 2026 SCORPIOX INC. */ #ifndef SX_PLUGIN_TIME_TZ_H #define SX_PLUGIN_TIME_TZ_H #include #include /* A wall-clock resolution can legitimately have two answers (a repeated hour * at a DST fall-back) or zero (an hour skipped at spring-forward). */ #define TZ_MAX_CANDIDATES 4 typedef struct { int64_t utc; int offset; /* east of UTC, seconds */ int is_dst; } tz_cand_t; /* The zone record, opaque outside tz.c. */ typedef struct tz_zone tz_zone; /* The zone's IANA key (valid while the table is loaded). */ const char *tz_zone_name(const tz_zone *z); /* Exact IANA key lookup. Case sensitive on every platform on purpose: see the * header comment in tools/gen_tzdata.py. Returns NULL for an unknown key. */ const tz_zone *tz_find(const char *name); /* Windows timezone id ("New Zealand Standard Time") -> IANA key, via the * CLDR map embedded in the table. Returns NULL when the id is unknown. */ const tz_zone *tz_find_windows(const char *win_id); /* Number of embedded zones and their keys (sorted), for the picker UI. */ int tz_count(void); const char *tz_name_at(int index); /* Offset east of UTC in force at `utc`. `abbr` (may be NULL) receives the * zone abbreviation, truncated to `abbrsz` including the terminator. */ int tz_offset(const tz_zone *z, int64_t utc, int *is_dst, char *abbr, size_t abbrsz); /* Every UTC instant that has the given wall-clock time in `z`, earliest * first. `wall` is the local time read as if it were UTC (i.e. it already * includes the date and the hh:mm:ss). Returns the count: * 0 = the wall time does not exist (skipped by a forward clock change) * 1 = unambiguous * 2 = the hour repeated (a backward clock change); [0] is the first * occurrence, [1] the second - which is what Python's fold=0/1 gives. */ int tz_resolve_wall(const tz_zone *z, int64_t wall, tz_cand_t *out, int outmax); /* The node's own IANA zone name, best effort: $TZ, then the platform's own * configuration, then an offset match against the embedded table. Never * returns NULL; falls back to "UTC". The result is always a name tz_find() * accepts. */ const char *tz_local_name(void); /* Civil-date helpers (proleptic Gregorian, no leap seconds). */ int64_t tz_days_from_civil(int y, int m, int d); void tz_civil_from_days(int64_t days, int *y, int *m, int *d); int tz_weekday(int64_t days); /* 0 = Sunday */ #endif /* SX_PLUGIN_TIME_TZ_H */