Skip to content

Commit e49132e

Browse files
committed
Tweak our special-case logic for the IANA "Factory" timezone.
pg_timezone_names() tries to avoid showing the "Factory" zone in the view, mainly because that has traditionally had a very long "abbreviation" such as "Local time zone must be set--see zic manual page", so that showing it messes up psql's formatting of the whole view. Since tzdb version 2016g, IANA instead uses the abbreviation "-00", which is sane enough that there's no reason to discriminate against it. On the other hand, it emerges that FreeBSD and possibly other packagers are so wedded to backwards compatibility that they hack the IANA data to keep the old spelling --- and not just that old spelling, but even older spellings that IANA used back in the stone age. This caused the filter logic to fail to suppress "Factory" at all on such platforms, though the formatting problem is definitely real in that case. To solve both problems, get rid of the hard-wired assumption about exactly what Factory's abbreviation is, and instead reject abbreviations exceeding 31 characters. This will allow Factory to appear in the view if and only if it's using the modern abbreviation. In passing, simplify the code we add to zic.c to support "zic -P" to remove its now-obsolete hacks to not print the Factory zone's abbreviation. Unlike pg_timezone_names(), there's no reason for that code to support old/nonstandard timezone data. Since we generally prefer to keep timezone-related behavior the same in all branches, and since this is arguably a bug fix, back-patch to all supported branches. Discussion: https://postgr.es/m/3961.1564086915@sss.pgh.pa.us
1 parent 6c4ffab commit e49132e

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

src/backend/utils/adt/datetime.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4827,16 +4827,15 @@ pg_timezone_names(PG_FUNCTION_ARGS)
48274827
continue; /* ignore if conversion fails */
48284828

48294829
/*
4830-
* Ignore zic's rather silly "Factory" time zone. The long string
4831-
* about "see zic manual page" is used in tzdata versions before
4832-
* 2016g; we can drop it someday when we're pretty sure no such data
4833-
* exists in the wild on platforms using --with-system-tzdata. In
4834-
* 2016g and later, the time zone abbreviation "-00" is used for
4835-
* "Factory" as well as some invalid cases, all of which we can
4836-
* reasonably omit from the pg_timezone_names view.
4830+
* IANA's rather silly "Factory" time zone used to emit ridiculously
4831+
* long "abbreviations" such as "Local time zone must be set--see zic
4832+
* manual page" or "Local time zone must be set--use tzsetup". While
4833+
* modern versions of tzdb emit the much saner "-00", it seems some
4834+
* benighted packagers are hacking the IANA data so that it continues
4835+
* to produce these strings. To prevent producing a weirdly wide
4836+
* abbrev column, reject ridiculously long abbreviations.
48374837
*/
4838-
if (tzn && (strcmp(tzn, "-00") == 0 ||
4839-
strcmp(tzn, "Local time zone must be set--see zic manual page") == 0))
4838+
if (tzn && strlen(tzn) > 31)
48404839
continue;
48414840

48424841
/* Found a displayable zone */

src/timezone/zic.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,13 +2451,10 @@ writezone(const char *const name, const char *const string, char version,
24512451
unsigned char tm = types[i];
24522452
char *thisabbrev = &thischars[indmap[desigidx[tm]]];
24532453

2454-
/* filter out assorted junk entries */
2455-
if (strcmp(thisabbrev, GRANDPARENTED) != 0 &&
2456-
strcmp(thisabbrev, "zzz") != 0)
2457-
fprintf(stdout, "%s\t" INT64_FORMAT "%s\n",
2458-
thisabbrev,
2459-
utoffs[tm],
2460-
isdsts[tm] ? "\tD" : "");
2454+
fprintf(stdout, "%s\t" INT64_FORMAT "%s\n",
2455+
thisabbrev,
2456+
utoffs[tm],
2457+
isdsts[tm] ? "\tD" : "");
24612458
}
24622459
}
24632460
/* Print the default type if we have no transitions at all */
@@ -2466,13 +2463,10 @@ writezone(const char *const name, const char *const string, char version,
24662463
unsigned char tm = defaulttype;
24672464
char *thisabbrev = &thischars[indmap[desigidx[tm]]];
24682465

2469-
/* filter out assorted junk entries */
2470-
if (strcmp(thisabbrev, GRANDPARENTED) != 0 &&
2471-
strcmp(thisabbrev, "zzz") != 0)
2472-
fprintf(stdout, "%s\t" INT64_FORMAT "%s\n",
2473-
thisabbrev,
2474-
utoffs[tm],
2475-
isdsts[tm] ? "\tD" : "");
2466+
fprintf(stdout, "%s\t" INT64_FORMAT "%s\n",
2467+
thisabbrev,
2468+
utoffs[tm],
2469+
isdsts[tm] ? "\tD" : "");
24762470
}
24772471
}
24782472

0 commit comments

Comments
 (0)