pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Christoph Berg <myon@debian.org>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Subject: Re: UCT (Re: pgsql: Update time zone data files to tzdata release 2019a.)
Date: Fri, 14 Jun 2019 23:14:09 +0100
Message-ID: <871rzv4yes.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <875zp74zpf.fsf@news-spur.riddles.org.uk>
References: <E1hK8qL-0005yH-VX@gemulon.postgresql.org>
	<20190604085735.GD24018@msg.df7cb.de>
	<65800.1559662051@sss.pgh.pa.us>
	<20190605084735.GC15829@msg.df7cb.de>
	<24452.1560285699@sss.pgh.pa.us>
	<20190614095546.GA15107@msg.df7cb.de>
	<26948.1560517875@sss.pgh.pa.us>
	<87ef3w3u8a.fsf@news-spur.riddles.org.uk>
	<7114.1560539536@sss.pgh.pa.us>
	<875zp74zpf.fsf@news-spur.riddles.org.uk>

>>>>> "Andrew" == Andrew Gierth <andrew@tao11.riddles.org.uk> writes:
>>>>> "Tom" == Tom Lane <tgl@sss.pgh.pa.us> writes:

 >>> This isn't good enough, because it still picks "UCT" on a system
 >>> with no /etc/localtime and no TZ variable. Testing on HEAD as of
 >>> 3da73d683 (on FreeBSD, but it'll be the same anywhere else):

 Tom> [ shrug... ]  Too bad.  I doubt that that's a common situation anyway.

 Andrew> I'm also reminded that this applies also if the /etc/localtime
 Andrew> file is a _copy_ of the UTC zonefile rather than a symlink,
 Andrew> which is possibly even more common.

And testing shows that if you select "UTC" when installing FreeBSD, you
indeed get /etc/localtime as a copy not a symlink, and I've confirmed
that initdb picks "UCT" in that case.

So here is my current proposed fix.

-- 
Andrew (irc:RhodiumToad)

Attachments:

utcpref.patch (text/x-patch, 2.5K) download diff --git a/src/bin/initdb/findtimezone.c b/src/bin/initdb/findtimezone.c index 3477a08efd..f7c199a006 100644 --- a/src/bin/initdb/findtimezone.c +++ b/src/bin/initdb/findtimezone.c @@ -128,8 +128,11 @@ pg_load_tz(const char *name) * the C library's localtime() function. The database zone that matches * furthest into the past is the one to use. Often there will be several * zones with identical rankings (since the IANA database assigns multiple - * names to many zones). We break ties arbitrarily by preferring shorter, - * then alphabetically earlier zone names. + * names to many zones). We break ties by first checking for "preferred" + * names (such as "UTC"), and then arbitrarily by preferring shorter, then + * alphabetically earlier zone names. (If we did not explicitly prefer + * "UTC", we would get the alias name "UCT" instead due to alphabetic + * ordering.) * * Many modern systems use the IANA database, so if we can determine the * system's idea of which zone it is using and its behavior matches our zone @@ -602,6 +605,28 @@ check_system_link_file(const char *linkname, struct tztry *tt, #endif } +/* + * Given a timezone name, determine whether it should be preferred over other + * names which are equally good matches. The output is arbitrary but we will + * use 0 for "neutral" default preference. + * + * Ideally we'd prefer the zone.tab/zone1970.tab names, since in general those + * are the ones offered to the user to select from. But for the moment, to + * minimize changes in behaviour, simply prefer UTC over alternative spellings + * such as UCT that otherwise cause confusion. The existing "shortest first" + * rule would prefer "UTC" over "Etc/UTC" so keep that the same way (while + * still preferring Etc/UTC over Etc/UCT). + */ +static int +zone_name_pref(const char *zonename) +{ + if (strcmp(zonename, "UTC") == 0) + return 50; + if (strcmp(zonename, "Etc/UTC") == 0) + return 40; + return 0; +} + /* * Recursively scan the timezone database looking for the best match to * the system timezone behavior. @@ -674,7 +699,8 @@ scan_available_timezones(char *tzdir, char *tzdirsub, struct tztry *tt, else if (score == *bestscore) { /* Consider how to break a tie */ - if (strlen(tzdirsub) < strlen(bestzonename) || + if (zone_name_pref(tzdirsub) > zone_name_pref(bestzonename) || + strlen(tzdirsub) < strlen(bestzonename) || (strlen(tzdirsub) == strlen(bestzonename) && strcmp(tzdirsub, bestzonename) < 0)) strlcpy(bestzonename, tzdirsub, TZ_STRLEN_MAX + 1);

view thread (74+ messages)  latest in thread

Message-ID: <871rzv4yes.fsf@news-spur.riddles.org.uk>
Permalink:  ../871rzv4yes.fsf@news-spur.riddles.org.uk/
Also on:    postgresql.org/message-id/871rzv4yes.fsf@news-spur.riddles.org.uk

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: andrew@tao11.riddles.org.uk, tgl@sss.pgh.pa.us, myon@debian.org, pgsql-hackers@postgresql.org
  Subject: Re: UCT (Re: pgsql: Update time zone data files to tzdata release 2019a.)
  In-Reply-To: <871rzv4yes.fsf@news-spur.riddles.org.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox