/* * tz.c - IANA timezone resolution over the embedded table (src/tzdata.h). * * The design mirrors what the OS does, in three steps: * * 1. Look the zone up in the exact-key table. Never a filesystem path, so * `europe/warsaw` is refused on every platform instead of only on the * case-sensitive ones. * 2. Answer a UTC instant from the embedded transition list, falling back * to the zone's own POSIX TZ footer string beyond the last embedded * transition - exactly what zoneinfo itself does after it runs out of * the compiled table. * 3. For a wall-clock instant the caller supplies (the `convert_time` * tool), find the UTC instants that map to it. A forward clock change * makes a wall time that does not exist (0 candidates); a backward * change repeats an hour (2 candidates). Guessing one silently is how a * converter reports a time that never happened. * * Nothing here reads the clock: every function is a pure function of its * arguments, so a test can pin a date in 2035 and get the same answer on * Linux, macOS and Windows. * * MIT License. Copyright (c) 2026 SCORPIOX INC. */ #if defined(_WIN32) && !defined(_WIN32_WINNT) # define _WIN32_WINNT 0x0601 #endif #if !defined(_WIN32) # define _POSIX_C_SOURCE 200809L # define _DEFAULT_SOURCE 1 # if defined(__APPLE__) # define _DARWIN_C_SOURCE 1 # endif #endif #include #include #include #include #include #if defined(_WIN32) # define WIN32_LEAN_AND_MEAN # include #else # include # include #endif #include "tz.h" #include "tzdata.h" /* ------------------------------------------------------------------ */ /* The zone record */ /* */ /* tz_zone is the generated struct plus the name pointer, so callers */ /* never index the string pool themselves. */ /* ------------------------------------------------------------------ */ struct tz_zone { const char *name; const tz_zone_t *rec; int index; }; static tz_zone *g_zones = NULL; static int g_nzones = 0; static void zones_build(void) { int i; if (g_zones) return; g_zones = (tz_zone *)calloc((size_t)TZ_ZONE_COUNT, sizeof *g_zones); if (!g_zones) return; for (i = 0; i < TZ_ZONE_COUNT; i++) { g_zones[i].name = TZ_NAME_POOL + TZ_ZONES[i].name; g_zones[i].rec = &TZ_ZONES[i]; g_zones[i].index = i; } g_nzones = TZ_ZONE_COUNT; } const char *tz_zone_name(const tz_zone *z) { return z ? z->name : NULL; } int tz_count(void) { zones_build(); return g_nzones; } const char *tz_name_at(int index) { zones_build(); if (index < 0 || index >= g_nzones) return NULL; return g_zones[index].name; } const tz_zone *tz_find(const char *name) { int lo, hi; if (!name || !*name) return NULL; /* An IANA key can never contain these: refused before any search so a * path, a traversal or a `..` cannot be mistaken for a zone. */ if (strstr(name, "..") || strchr(name, '\\') || strchr(name, '\n') || strchr(name, '\r') || strchr(name, '%')) return NULL; if (name[0] == '/' || name[0] == '.' || name[0] == ' ') return NULL; if (strlen(name) > 96) return NULL; zones_build(); if (!g_zones) return NULL; /* The generated table is sorted by key, so this is a plain binary search * with a case-sensitive compare - the whole point of the exact match. */ lo = 0; hi = g_nzones - 1; while (lo <= hi) { int mid = lo + (hi - lo) / 2; int cmp = strcmp(name, g_zones[mid].name); if (cmp == 0) return &g_zones[mid]; if (cmp < 0) hi = mid - 1; else lo = mid + 1; } return NULL; } const tz_zone *tz_find_windows(const char *win_id) { int i; if (!win_id || !*win_id) return NULL; zones_build(); if (!g_zones) return NULL; for (i = 0; i < TZ_WIN_COUNT; i++) { if (strcmp(TZ_WIN_POOL + TZ_WIN_ZONES[i].win, win_id) != 0) continue; { const char *iana = TZ_NAME_POOL + TZ_WIN_ZONES[i].zone; return tz_find(iana); } } return NULL; } /* ------------------------------------------------------------------ */ /* Civil date arithmetic (proleptic Gregorian, days since 1970-01-01) */ /* ------------------------------------------------------------------ */ int64_t tz_days_from_civil(int y, int m, int d) { int64_t era, yoe, doy, doe; y -= (m <= 2); era = (y >= 0 ? y : y - 399) / 400; yoe = y - era * 400; /* 0..399 */ doy = (153 * (m + (m > 2 ? -3 : 9)) + 2) / 5 + d - 1; /* 0..365 */ doe = yoe * 365 + yoe / 4 - yoe / 100 + doy; /* 0..146096 */ return era * 146097 + doe - 719468; } void tz_civil_from_days(int64_t days, int *y, int *m, int *d) { int64_t z, era, doe, yoe, doy, mp; int yy, mm, dd; z = days + 719468; era = (z >= 0 ? z : z - 146096) / 146097; doe = z - era * 146097; yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365; yy = (int)(yoe + era * 400); doy = doe - (365 * yoe + yoe / 4 - yoe / 100); mp = (5 * doy + 2) / 153; dd = (int)(doy - (153 * mp + 2) / 5 + 1); mm = (int)(mp + (mp < 10 ? 3 : -9)); if (y) *y = yy + (mm <= 2); if (m) *m = mm; if (d) *d = dd; } int tz_weekday(int64_t days) { /* 1970-01-01 was a Thursday (4). */ int64_t w = (days + 4) % 7; if (w < 0) w += 7; return (int)w; } /* ------------------------------------------------------------------ */ /* POSIX TZ footer strings */ /* */ /* Beyond the last embedded transition the tz database defers to the */ /* zone's own rule string, e.g. */ /* NZST-12NZDT,M9.5.0,M4.1.0/3 (Auckland) */ /* EST5EDT,M3.2.0,M11.1.0 (New York) */ /* <-02>2<-01>,M3.5.0/-1,M10.5.0/0 (Godthab) */ /* <+00>0<+01>,0/0,J365/25 (Casablanca, Ramadan) */ /* */ /* Offsets in the string are WEST positive, so the east-of-UTC offset we */ /* store everywhere else is the negation. */ /* ------------------------------------------------------------------ */ typedef struct { int kind; /* 0 = Jn, 1 = n (zero-based), 2 = Mm.w.d */ int n; /* Jn / n value, or the day-of-week for rules kind 2 */ int week; /* kind 2: 1..5 (5 = last) */ int month; /* kind 2 */ int time; /* seconds after local midnight, may be <0 or >86400 */ } rule_date; typedef struct { int ok; int std_off; /* east of UTC */ int dst_off; /* east of UTC */ int has_dst; rule_date start, end; } posix_tz; static const char *pz_name(const char *s, char *out, size_t outsz) { size_t n = 0; if (*s == '<') { s++; while (*s && *s != '>') { if (n + 1 < outsz) out[n++] = *s; s++; } if (*s == '>') s++; } else { while (*s && isalpha((unsigned char)*s)) { if (n + 1 < outsz) out[n++] = *s; s++; } } out[n] = '\0'; return s; } static const char *pz_offset(const char *s, int *out, int *found) { int sign = 1, h = 0, m = 0, sec = 0; *found = 0; if (*s == '+' || *s == '-') { if (*s == '-') sign = -1; s++; } if (!isdigit((unsigned char)*s) && *s != ':') return s; while (isdigit((unsigned char)*s)) { h = h * 10 + (*s - '0'); s++; } if (*s == ':') { s++; while (isdigit((unsigned char)*s)) { m = m * 10 + (*s - '0'); s++; } if (*s == ':') { s++; while (isdigit((unsigned char)*s)) { sec = sec * 10 + (*s - '0'); s++; } } } *out = sign * (h * 3600 + m * 60 + sec); *found = 1; return s; } static const char *pz_time_of_day(const char *s, int *out) { int sign = 1, h = 0, m = 0, sec = 0; if (*s == '+' || *s == '-') { if (*s == '-') sign = -1; s++; } while (isdigit((unsigned char)*s)) { h = h * 10 + (*s - '0'); s++; } if (*s == ':') { s++; while (isdigit((unsigned char)*s)) { m = m * 10 + (*s - '0'); s++; } if (*s == ':') { s++; while (isdigit((unsigned char)*s)) { sec = sec * 10 + (*s - '0'); s++; } } } *out = sign * (h * 3600 + m * 60 + sec); return s; } static const char *pz_rule(const char *s, rule_date *r) { memset(r, 0, sizeof *r); r->time = 2 * 3600; /* POSIX default: 02:00 local */ if (*s == 'M') { int m = 0, w = 0, d = 0; s++; while (isdigit((unsigned char)*s)) { m = m * 10 + (*s - '0'); s++; } if (*s == '.') s++; while (isdigit((unsigned char)*s)) { w = w * 10 + (*s - '0'); s++; } if (*s == '.') s++; while (isdigit((unsigned char)*s)) { d = d * 10 + (*s - '0'); s++; } r->kind = 2; r->month = m; r->week = w; r->n = d; } else if (*s == 'J') { int n = 0; s++; while (isdigit((unsigned char)*s)) { n = n * 10 + (*s - '0'); s++; } r->kind = 0; r->n = n; } else { int n = 0; while (isdigit((unsigned char)*s)) { n = n * 10 + (*s - '0'); s++; } r->kind = 1; r->n = n; } if (*s == '/') s = pz_time_of_day(s + 1, &r->time); return s; } static int posix_parse(const char *s, posix_tz *p) { int found = 0; char nm[24]; memset(p, 0, sizeof *p); if (!s || !*s || *s == '\n') return -1; s = pz_name(s, nm, sizeof nm); if (!nm[0]) return -1; s = pz_offset(s, &p->std_off, &found); if (!found) return -1; p->std_off = -p->std_off; /* west -> east */ if (*s && *s != ',' && *s != '\n') { s = pz_name(s, nm, sizeof nm); if (!nm[0]) return -1; p->has_dst = 1; if (*s == '+' || *s == '-' || isdigit((unsigned char)*s)) { int v = 0; s = pz_offset(s, &v, &found); if (!found) return -1; p->dst_off = -v; } else { p->dst_off = p->std_off + 3600; /* POSIX default +1h */ } } if (p->has_dst) { if (*s != ',') return -1; /* a DST zone without rules * is not in the shipped * database; refuse rather * than guess */ s = pz_rule(s + 1, &p->start); if (*s != ',') return -1; s = pz_rule(s + 1, &p->end); } p->ok = 1; return 0; } /* The date a rule names in `year`, as days since the epoch. */ static int64_t rule_day(const rule_date *r, int year) { int64_t jan1 = tz_days_from_civil(year, 1, 1); if (r->kind == 0) { /* Jn: 1..365, no Feb 29 */ int leap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); int doy = r->n - 1; if (leap && r->n >= 60) doy += 1; return jan1 + doy; } if (r->kind == 1) { /* n: 0..365, Feb 29 counts */ return jan1 + r->n; } { /* Mm.w.d: day d (0=Sunday) of week w of month m; w=5 means last. */ int64_t first = tz_days_from_civil(year, r->month, 1); int wd = tz_weekday(first); int delta = (r->n - wd + 7) % 7; int64_t day = first + delta + (int64_t)(r->week - 1) * 7; int y2, m2, d2; tz_civil_from_days(day, &y2, &m2, &d2); while (m2 != r->month) { /* week 5 spilled over */ day -= 7; tz_civil_from_days(day, &y2, &m2, &d2); } return day; } } /* The UTC instant `year`'s rule fires at, given the offset in force before it. */ static int64_t rule_utc(const rule_date *r, int year, int before_east) { return rule_day(r, year) * 86400 + r->time - before_east; } static int posix_is_dst(const posix_tz *p, int64_t utc) { /* The rule names two instants per year; DST is in force after a start * event and before the next end event. Sorting the events of the * surrounding years and taking the last one at or before `utc` handles a * northern rule, a southern rule (start after end within a year) and a * rule whose changeovers sit at 24:00 or -01:00 without a special case * for any of them. The earlier "does the window contain utc" form * answered DST forever after a southern zone's start date, because * "utc >= start of last season" stays true for the rest of the year. */ struct { int64_t t; int on; } ev[9]; int n = 0, i, j, k; int year, month, day; if (!p->has_dst) return 0; tz_civil_from_days((utc + p->std_off) / 86400, &year, &month, &day); for (k = -1; k <= 1; k++) { int y = year + k; if (n < 8) { ev[n].t = rule_utc(&p->start, y, p->std_off); ev[n++].on = 1; } if (n < 8) { ev[n].t = rule_utc(&p->end, y, p->dst_off); ev[n++].on = 0; } } for (i = 1; i < n; i++) { /* insertion sort, n <= 9 */ for (j = i; j > 0 && ev[j - 1].t > ev[j].t; j--) { int64_t t = ev[j].t; int on = ev[j].on; ev[j].t = ev[j - 1].t; ev[j].on = ev[j - 1].on; ev[j - 1].t = t; ev[j - 1].on = on; } } for (i = n - 1; i >= 0; i--) if (ev[i].t <= utc) return ev[i].on; return 0; } /* ------------------------------------------------------------------ */ /* Offset lookup */ /* ------------------------------------------------------------------ */ static int zone_abbr(const tz_zone *z, uint16_t off, char *abbr, size_t sz) { const char *a = TZ_ABBR_POOL + off; if (abbr && sz) { size_t n = strlen(a); if (n >= sz) n = sz - 1; memcpy(abbr, a, n); abbr[n] = '\0'; } (void)z; return 0; } int tz_offset(const tz_zone *z, int64_t utc, int *is_dst, char *abbr, size_t abbrsz) { const tz_zone_t *r; int64_t rel; int lo, hi, hit; posix_tz pz; if (!z) return 0; r = z->rec; if (utc < TZ_WINDOW_EPOCH) { if (is_dst) *is_dst = r->base_dst; zone_abbr(z, r->base_abbr, abbr, abbrsz); return r->base_off; } rel = utc - TZ_WINDOW_EPOCH; /* Last transition at or before `rel` inside this zone's slice. */ lo = 0; hi = (int)r->count - 1; hit = -1; while (lo <= hi) { int mid = lo + (hi - lo) / 2; uint32_t t = TZ_TR_T[r->first + (uint32_t)mid]; if ((int64_t)t <= rel) { hit = mid; lo = mid + 1; } else { hi = mid - 1; } } if (hit >= 0) { uint32_t i = r->first + (uint32_t)hit; /* A query PAST this zone's last embedded transition must go to the * POSIX rule below, not to the last row: the last row is whatever * state the tz database stopped generating transitions in, and for * most zones that is standard time in 2037. Returning it made every * zone answer "no DST" from 2038 on - valid JSON, wrong answer, * forever. */ int past_last = (r->count > 0 && (int64_t)TZ_TR_T[r->first + r->count - 1] < rel); if (!(r->has_rule && past_last)) { if (is_dst) *is_dst = TZ_TR_DST[i] ? 1 : 0; zone_abbr(z, TZ_TR_ABBR[i], abbr, abbrsz); return TZ_TR_OFF[i]; } } /* Before this zone's first embedded transition but after the window * start: the base state still holds. */ if (r->count == 0 || rel < (int64_t)TZ_TR_T[r->first]) { /* Only fall through to the POSIX rule when we are past the zone's * last transition (a zone whose slice is empty uses base forever). */ if (r->count == 0) { if (is_dst) *is_dst = r->base_dst; zone_abbr(z, r->base_abbr, abbr, abbrsz); return r->base_off; } } /* Past the last embedded transition: the zone's own POSIX rule decides, * which is exactly how a host with less tzdata behaves. */ if (r->has_rule && posix_parse(TZ_RULE_POOL + r->rule, &pz) == 0) { int dst = posix_is_dst(&pz, utc); if (is_dst) *is_dst = dst; if (abbr && abbrsz) { /* Reuse the abbreviation of the most recent embedded transition * that had the same DST state; that is the name the zone uses. */ int i; const char *best = NULL; for (i = (int)r->count - 1; i >= 0; i--) { uint32_t j = r->first + (uint32_t)i; if ((TZ_TR_DST[j] ? 1 : 0) == dst) { best = TZ_ABBR_POOL + TZ_TR_ABBR[j]; break; } } if (!best) best = TZ_ABBR_POOL + r->base_abbr; { size_t n = strlen(best); if (n >= abbrsz) n = abbrsz - 1; memcpy(abbr, best, n); abbr[n] = '\0'; } } return dst ? pz.dst_off : pz.std_off; } if (is_dst) *is_dst = r->base_dst; zone_abbr(z, r->base_abbr, abbr, abbrsz); return r->base_off; } /* ------------------------------------------------------------------ */ /* Wall clock -> UTC */ /* */ /* Every distinct offset in force anywhere near `wall` is a candidate; */ /* an offset is valid only if applying it lands on an instant whose */ /* offset is that same value. That test is what distinguishes the two */ /* readings of a repeated hour from a time that never happened. */ /* ------------------------------------------------------------------ */ static int cand_push(tz_cand_t *out, int n, int max, int64_t utc, int off, int dst) { int i; for (i = 0; i < n; i++) if (out[i].utc == utc) return n; if (n >= max) return n; out[n].utc = utc; out[n].offset = off; out[n].is_dst = dst; return n + 1; } static int cand_cmp(const void *a, const void *b) { int64_t x = ((const tz_cand_t *)a)->utc; int64_t y = ((const tz_cand_t *)b)->utc; return (x < y) ? -1 : (x > y) ? 1 : 0; } int tz_resolve_wall(const tz_zone *z, int64_t wall, tz_cand_t *out, int outmax) { const tz_zone_t *r; int offs[TZ_MAX_CANDIDATES * 4]; int noffs = 0; int n = 0, i; int64_t probes[7]; int p; if (!z || !out || outmax <= 0) return 0; r = z->rec; /* Offsets in force just before and just after the wall time, plus every * transition within a two-day margin of it (a shift can be more than an * hour, and a rule can move the change across midnight). */ probes[0] = wall - 3 * 86400; probes[1] = wall - 86400; probes[2] = wall - 3600; probes[3] = wall; probes[4] = wall + 3600; probes[5] = wall + 86400; probes[6] = wall + 3 * 86400; for (p = 0; p < 7; p++) { int dst = 0; int o = tz_offset(z, probes[p], &dst, NULL, 0); int dup = 0; for (i = 0; i < noffs; i++) if (offs[i] == o) { dup = 1; break; } if (!dup && noffs < (int)(sizeof offs / sizeof offs[0])) offs[noffs++] = o; } { int64_t lo = wall - 3 * 86400, hi = wall + 3 * 86400; int64_t rel_lo = lo - TZ_WINDOW_EPOCH, rel_hi = hi - TZ_WINDOW_EPOCH; int j; for (j = 0; j < (int)r->count; j++) { uint32_t k = r->first + (uint32_t)j; int64_t t = (int64_t)TZ_TR_T[k]; if (t < rel_lo) continue; if (t > rel_hi) break; { int o = TZ_TR_OFF[k]; int dup = 0; for (i = 0; i < noffs; i++) if (offs[i] == o) { dup = 1; break; } if (!dup && noffs < (int)(sizeof offs / sizeof offs[0])) offs[noffs++] = o; } } } for (i = 0; i < noffs; i++) { int64_t utc = wall - offs[i]; int dst = 0; int o = tz_offset(z, utc, &dst, NULL, 0); if (o == offs[i]) n = cand_push(out, n, outmax, utc, o, dst); } qsort(out, (size_t)n, sizeof *out, cand_cmp); return n; } /* ------------------------------------------------------------------ */ /* The node's own zone */ /* ------------------------------------------------------------------ */ static char g_local_name[128]; static int g_local_done = 0; static int name_ok(const char *s) { return s && *s && tz_find(s) != NULL; } #if !defined(_WIN32) /* /etc/localtime is a symlink into the zoneinfo tree on most Linux hosts and * on macOS; the key is the tail of the link target after "zoneinfo/". */ static int name_from_localtime_link(void) { static const char *paths[2] = { "/etc/localtime", "/var/db/timezone/localtime" }; int i; for (i = 0; i < 2; i++) { char buf[PATH_MAX]; ssize_t n = readlink(paths[i], buf, sizeof buf - 1); const char *p; if (n <= 0) continue; buf[n] = '\0'; p = strstr(buf, "zoneinfo/"); if (p && name_ok(p + 9)) { snprintf(g_local_name, sizeof g_local_name, "%s", p + 9); return 1; } p = strstr(buf, "zoneinfo.default/"); if (p && name_ok(p + 16)) { snprintf(g_local_name, sizeof g_local_name, "%s", p + 16); return 1; } } return 0; } /* Debian/Ubuntu keep the key in /etc/timezone as plain text. */ static int name_from_etc_timezone(void) { char buf[128]; FILE *f = fopen("/etc/timezone", "r"); size_t n; if (!f) return 0; n = fread(buf, 1, sizeof buf - 1, f); fclose(f); if (n == 0) return 0; buf[n] = '\0'; while (n > 0 && (buf[n - 1] == '\n' || buf[n - 1] == '\r' || buf[n - 1] == ' ' || buf[n - 1] == '\t')) buf[--n] = '\0'; if (!name_ok(buf)) return 0; snprintf(g_local_name, sizeof g_local_name, "%s", buf); return 1; } #endif /* Offset-only fallback: the current local offset, DST state and - on POSIX - * the abbreviation, matched against the embedded table. An offset alone cannot * distinguish Europe/Paris (CET) from Africa/Lagos (WAT) in winter, so the * abbreviation is the discriminator where the platform reports one. A * "Region/City" key beats a bare legacy key (UTC, GMT, EST) so the answer is * stable and useful; the table is sorted, so it is deterministic. */ static int name_from_offset(void) { int64_t now = (int64_t)time(NULL); int off; int dst; int i; int fallback = -1; char abbr[24]; abbr[0] = '\0'; #if defined(_WIN32) { /* GetDynamicTimeZoneInformation, not GetTimeZoneInformation: the * latter's StandardName is LOCALISED ("Neuseeland Normalzeit" on a * German Windows), while TimeZoneKeyName is always the invariant * registry id every CLDR row is keyed on. Falling back to the old call * keeps a pre-Vista build working. */ DYNAMIC_TIME_ZONE_INFORMATION tz; DWORD kind = GetDynamicTimeZoneInformation(&tz); long bias; char id[128]; bias = tz.Bias + ((kind == TIME_ZONE_ID_DAYLIGHT) ? tz.DaylightBias : tz.StandardBias); if (kind == TIME_ZONE_ID_INVALID) { off = 0; dst = 0; } off = (int)(-bias * 60); dst = (kind == TIME_ZONE_ID_DAYLIGHT); /* The registry name is the authoritative answer: it names a region, * where an offset names a band shared by a dozen of them. CLDR's map * turns it into the same IANA key every other platform reports. * StandardName is the key CLDR carries ("New Zealand Standard Time"), * so it is tried first; DaylightName ("... Daylight Time") is only a * fallback for a map that happens to carry one. */ WideCharToMultiByte(CP_UTF8, 0, tz.TimeZoneKeyName, -1, id, sizeof id, NULL, NULL); if (tz_find_windows(id)) { snprintf(g_local_name, sizeof g_local_name, "%s", tz_zone_name(tz_find_windows(id))); return 1; } WideCharToMultiByte(CP_UTF8, 0, tz.StandardName, -1, id, sizeof id, NULL, NULL); if (tz_find_windows(id)) { snprintf(g_local_name, sizeof g_local_name, "%s", tz_zone_name(tz_find_windows(id))); return 1; } } #else { time_t t = (time_t)now; struct tm lt; if (!localtime_r(&t, <)) return 0; off = (int)lt.tm_gmtoff; dst = lt.tm_isdst > 0; if (lt.tm_zone) snprintf(abbr, sizeof abbr, "%s", lt.tm_zone); } #endif for (i = 0; i < tz_count(); i++) { const tz_zone *z = tz_find(tz_name_at(i)); const char *nm = tz_name_at(i); char za[24]; int d = 0; int o; if (!z) continue; o = tz_offset(z, now, &d, za, sizeof za); if (o != off || d != dst) continue; if (abbr[0] && strcmp(za, abbr) != 0) continue; if (!strchr(nm, '/')) { if (fallback < 0) fallback = i; continue; } fallback = i; break; } if (fallback >= 0) { snprintf(g_local_name, sizeof g_local_name, "%s", tz_name_at(fallback)); return 1; } return 0; } const char *tz_local_name(void) { const char *env; if (g_local_done) return g_local_name; g_local_done = 1; env = getenv("TZ"); if (env && *env) { if (env[0] == ':') env++; if (name_ok(env)) { snprintf(g_local_name, sizeof g_local_name, "%s", env); return g_local_name; } } #if !defined(_WIN32) if (name_from_localtime_link()) return g_local_name; if (name_from_etc_timezone()) return g_local_name; #endif if (name_from_offset()) return g_local_name; snprintf(g_local_name, sizeof g_local_name, "UTC"); return g_local_name; }