Without this fix, on the rare installations where time_t counts leap seconds (e.g., make REDO=right_only), ‘zdump -v America/Los_Angeles’ would output a transition like this: Sun Jan 1 00:00:26 2017 UT = Sat Dec 31 16:59:60 2016 PDT Sun Jan 1 00:00:27 2017 UT = Sat Dec 31 17:00:00 2016 PDT which is incorrect, as the left-hand column is TAI, not UT. With this patch, the same command outputs this instead: Sat Dec 31 23:59:60 2016 UT = Sat Dec 31 16:59:60 2016 PDT Sun Jan 1 00:00:00 2017 UT = Sat Dec 31 17:00:00 2016 PDT * NEWS: Mention this. * zdump.c (gmtzinit): Try "GMT" and fall back on "GMT0" rather than using "UTC0". --- NEWS | 4 ++++ zdump.c | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 559e96e..bccd6c2 100644 --- a/NEWS +++ b/NEWS @@ -86,6 +86,10 @@ Unreleased, experimental changes "EST5EDT,0/0,J365/25" or "". (Thanks to Michael Deckers for noting the possibility of POSIX conformance.) + When reading slim TZif files, zdump no longer mishandles leap + seconds on the rare platforms where time_t counts leap seconds, + fixing a bug introduced in 2014g. + zdump's -c and -t options are now consistently inclusive for the lower time bound and exclusive for the upper. Formerly they were inconsistent. (Confusion noted by Martin Burnicki.) diff --git a/zdump.c b/zdump.c index c29f059..dcad817 100644 --- a/zdump.c +++ b/zdump.c @@ -259,11 +259,23 @@ static void gmtzinit(void) { if (USE_LOCALTIME_RZ) { - static char const utc[] = "UTC0"; - gmtz = tzalloc(utc); + /* Try "GMT" first to find out whether this is one of the rare + platforms where time_t counts leap seconds; this works due to + the "Link Etc/GMT GMT" line in the "etcetera" file. If "GMT" + fails, fall back on "GMT0" which might be similar due to the + "Link Etc/GMT GMT0" line in the "backward" file, and which + should work on all POSIX platforms. The rest of zdump does not + use the "GMT" abbreviation that comes from this setting, so it + is OK to use "GMT" here rather than the more-modern "UTC" which + would not work on platforms that omit the "backward" file. */ + gmtz = tzalloc("GMT"); if (!gmtz) { - perror(utc); - exit(EXIT_FAILURE); + static char const gmt0[] = "GMT0"; + gmtz = tzalloc(gmt0); + if (!gmtz) { + perror(gmt0); + exit(EXIT_FAILURE); + } } } } -- 2.27.0