Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7f28fc8

Browse files
committed
Prefer timezone name "UTC" over alternative spellings.
tzdb 2019a made "UCT" a link to the "UTC" zone rather than a separatezone with its own abbreviation. Unfortunately, our code for choosing atimezone in initdb has an arbitrary preference for names earlier inthe alphabet, and so it would choose the spelling "UCT" over "UTC"when the system is running on a UTC zone.Commit23bd3ce was backpatched in order to address this issue, butthat code helps only when /etc/localtime exists as a symlink, and doesnothing to help on systems where /etc/localtime is a copy of a zonefile (as is the standard setup on FreeBSD and probably some otherplatforms too) or when /etc/localtime is simply absent (giving UTC asthe default).Accordingly, add a preference for the spelling "UTC", such that ifmultiple zone names have equally good content matches, we prefer thatname before applying the existing arbitrary rules. Also add a slightlylower preference for "Etc/UTC"; lower because that preserves theprevious behaviour of choosing the shorter name, but letting us stillchoose "Etc/UTC" over "Etc/UCT" when both exist but "UTC" doesnot (not common, but I've seen it happen).Backpatch all the way, because the tzdb change that sparked this issueis in those branches too.
1 parent0995cef commit7f28fc8

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

‎src/bin/initdb/findtimezone.c

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,11 @@ pg_load_tz(const char *name)
128128
* the C library's localtime() function. The database zone that matches
129129
* furthest into the past is the one to use. Often there will be several
130130
* zones with identical rankings (since the IANA database assigns multiple
131-
* names to many zones). We break ties arbitrarily by preferring shorter,
132-
* then alphabetically earlier zone names.
131+
* names to many zones). We break ties by first checking for "preferred"
132+
* names (such as "UTC"), and then arbitrarily by preferring shorter, then
133+
* alphabetically earlier zone names. (If we did not explicitly prefer
134+
* "UTC", we would get the alias name "UCT" instead due to alphabetic
135+
* ordering.)
133136
*
134137
* Many modern systems use the IANA database, so if we can determine the
135138
* 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,
602605
#endif
603606
}
604607

608+
/*
609+
* Given a timezone name, determine whether it should be preferred over other
610+
* names which are equally good matches. The output is arbitrary but we will
611+
* use 0 for "neutral" default preference.
612+
*
613+
* Ideally we'd prefer the zone.tab/zone1970.tab names, since in general those
614+
* are the ones offered to the user to select from. But for the moment, to
615+
* minimize changes in behaviour, simply prefer UTC over alternative spellings
616+
* such as UCT that otherwise cause confusion. The existing "shortest first"
617+
* rule would prefer "UTC" over "Etc/UTC" so keep that the same way (while
618+
* still preferring Etc/UTC over Etc/UCT).
619+
*/
620+
staticint
621+
zone_name_pref(constchar*zonename)
622+
{
623+
if (strcmp(zonename,"UTC")==0)
624+
return50;
625+
if (strcmp(zonename,"Etc/UTC")==0)
626+
return40;
627+
return0;
628+
}
629+
605630
/*
606631
* Recursively scan the timezone database looking for the best match to
607632
* the system timezone behavior.
@@ -674,9 +699,13 @@ scan_available_timezones(char *tzdir, char *tzdirsub, struct tztry *tt,
674699
elseif (score==*bestscore)
675700
{
676701
/* Consider how to break a tie */
677-
if (strlen(tzdirsub)<strlen(bestzonename)||
678-
(strlen(tzdirsub)==strlen(bestzonename)&&
679-
strcmp(tzdirsub,bestzonename)<0))
702+
intnamepref= (zone_name_pref(tzdirsub)-
703+
zone_name_pref(bestzonename));
704+
if (namepref>0||
705+
(namepref==0&&
706+
(strlen(tzdirsub)<strlen(bestzonename)||
707+
(strlen(tzdirsub)==strlen(bestzonename)&&
708+
strcmp(tzdirsub,bestzonename)<0))))
680709
strlcpy(bestzonename,tzdirsub,TZ_STRLEN_MAX+1);
681710
}
682711
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp