[tz] [PATCH 1/5] Move a few links to ‘backward’

Paul Eggert eggert at cs.ucla.edu
Mon Sep 26 00:32:17 UTC 2022


If a Link is just an alternate name, it’s not needed for zone.tab
and ‘backward’ is a better home for it anyway.  This helps improve
link checking.
* Makefile (check_links): Use new backcheck option.
* asia (Europe/Nicosia):
* etcetera (Etc/Universal, Etc/Zulu, Etc/Greenwich, Etc/GMT-0)
(Etc/GMT+0, Etc/GMT0):
* europe (Asia/Istanbul):
Move Link to ‘backward’.
* checklinks.awk: Add backcheck option, to check that
non-‘backward’ Links are next to the Zones they link to, and that
a Link is in a continental file if and only if it is in zone.tab.
Add a special case for GMT.
* etcetera (GMT): In vanguard form, now a Zone, not a Link,
since it’s the file the leap second code depends on.
(Etc/GMT): In vanguard form, now a link in ‘backward’ instead of a
Zone here.
* ziguard.awk: Support the vanguard form.
---
 Makefile       |  3 ++-
 NEWS           | 17 +++++++++++++++++
 asia           |  4 ----
 backward       | 26 ++++++++++++++++++++++++++
 checklinks.awk | 27 +++++++++++++++++++++++++++
 etcetera       | 17 +++++++----------
 europe         |  1 -
 theory.html    |  1 +
 zdump.c        |  4 ++--
 ziguard.awk    | 14 ++++++++++++++
 10 files changed, 96 insertions(+), 18 deletions(-)

diff --git a/Makefile b/Makefile
index b68f843..69cb704 100644
--- a/Makefile
+++ b/Makefile
@@ -823,7 +823,8 @@ check_sorted: backward backzone iso3166.tab zone.tab zone1970.tab
 		touch $@
 
 check_links:	checklinks.awk $(TDATA_TO_CHECK) tzdata.zi
-		$(AWK) -f checklinks.awk $(TDATA_TO_CHECK)
+		$(AWK) -f checklinks.awk -v backcheck=backward \
+		  $(TDATA_TO_CHECK)
 		$(AWK) -f checklinks.awk tzdata.zi
 		touch $@
 
diff --git a/NEWS b/NEWS
index 64327d0..1e22ef7 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,22 @@
 News for the tz database
 
+Unreleased, experimental changes
+
+  Briefly:
+    Move links to 'backward'.
+    In vanguard form, GMT is now a Zone and Etc/GMT a link.
+
+  Changes to data
+
+    Move links to 'backward' to ease and simplify link maintenance.
+    This affects generated data only if you use 'make BACKWARD='.
+
+    GMT is now a Zone and Etc/GMT a link instead of vice versa,
+    as GMT is needed for leap second support whereas Etc/GMT is not.
+    However, this change exposes a bug in TZUpdater 2.3.2 so it is
+    present only in vanguard form for now.
+
+
 Release 2022d - 2022-09-23 12:02:57 -0700
 
   Briefly:
diff --git a/asia b/asia
index e0daae0..5a33a8e 100644
--- a/asia
+++ b/asia
@@ -1172,10 +1172,6 @@ Zone	Asia/Famagusta	2:15:48	-	LMT	1921 Nov 14
 			3:00	-	+03	2017 Oct 29 1:00u
 			2:00	EUAsia	EE%sT
 
-# Classically, Cyprus belongs to Asia; e.g. see Herodotus, Histories, I.72.
-# However, for various reasons many users expect to find it under Europe.
-Link	Asia/Nicosia	Europe/Nicosia
-
 # Georgia
 # From Paul Eggert (1994-11-19):
 # Today's _Economist_ (p 60) reports that Georgia moved its clocks forward
diff --git a/backward b/backward
index 14e4b14..517ec89 100644
--- a/backward
+++ b/backward
@@ -43,6 +43,8 @@ Link	Asia/Shanghai		Asia/Chongqing
 Link	Asia/Shanghai		Asia/Chungking
 Link	Asia/Dhaka		Asia/Dacca
 Link	Asia/Shanghai		Asia/Harbin
+# Istanbul is in both continents.
+Link	Europe/Istanbul		Asia/Istanbul
 Link	Asia/Urumqi		Asia/Kashgar
 Link	Asia/Kathmandu		Asia/Katmandu
 Link	Asia/Macau		Asia/Macao
@@ -86,18 +88,42 @@ Link	Pacific/Easter		Chile/EasterIsland
 Link	America/Havana		Cuba
 Link	Africa/Cairo		Egypt
 Link	Europe/Dublin		Eire
+# Vanguard section, for most .zi parsers.
+#Link	GMT			Etc/GMT
+#Link	GMT			Etc/GMT+0
+#Link	GMT			Etc/GMT-0
+#Link	GMT			Etc/GMT0
+#Link	GMT			Etc/Greenwich
+# Rearguard section, for TZUpdater 2.3.2 and earlier.
+Link	Etc/GMT			Etc/GMT+0
+Link	Etc/GMT			Etc/GMT-0
+Link	Etc/GMT			Etc/GMT0
+Link	Etc/GMT			Etc/Greenwich
+# End of rearguard section.
 Link	Etc/UTC			Etc/UCT
+Link	Etc/UTC			Etc/Universal
+Link	Etc/UTC			Etc/Zulu
 Link	Europe/London		Europe/Belfast
 Link	Europe/Kyiv		Europe/Kiev
+# Classically, Cyprus is in Asia; e.g. see Herodotus, Histories, I.72.
+# However, for various reasons many users expect to find it under Europe.
+Link	Asia/Nicosia		Europe/Nicosia
 Link	Europe/Chisinau		Europe/Tiraspol
 Link	Europe/Kyiv		Europe/Uzhgorod
 Link	Europe/Kyiv		Europe/Zaporozhye
 Link	Europe/London		GB
 Link	Europe/London		GB-Eire
+# Vanguard section, for most .zi parsers.
+#Link	GMT			GMT+0
+#Link	GMT			GMT-0
+#Link	GMT			GMT0
+#Link	GMT			Greenwich
+# Rearguard section, for TZUpdater 2.3.2 and earlier.
 Link	Etc/GMT			GMT+0
 Link	Etc/GMT			GMT-0
 Link	Etc/GMT			GMT0
 Link	Etc/GMT			Greenwich
+# End of rearguard section.
 Link	Asia/Hong_Kong		Hongkong
 Link	Africa/Abidjan		Iceland
 Link	Asia/Tehran		Iran
diff --git a/checklinks.awk b/checklinks.awk
index f309010..45f67e3 100644
--- a/checklinks.awk
+++ b/checklinks.awk
@@ -7,6 +7,18 @@ BEGIN {
     # It is a newline so that it cannot match a valid name.
     # It is not null so that its slot does not appear unset.
     Zone = "\n"
+
+    if (!zone_table) zone_table = "zone.tab"
+
+    while (getline <zone_table) {
+	if (/^#/) continue
+	zone_cc[$3] = $1
+    }
+
+    # As a special case, a link to "GMT" is allowed in a continental file.
+    # Remove this special case once the hack for TZUpdater 2.3.2 is
+    # moved from main to reaguard form.
+    zone_cc["GMT"] = 1
 }
 
 /^Z/ {
@@ -19,6 +31,7 @@ BEGIN {
 	status = 1
     }
     defined[$2] = Zone
+    last_zone = $2
 }
 
 /^L/ {
@@ -32,6 +45,20 @@ BEGIN {
 	}
 	status = 1
     }
+    if (backcheck) {
+	backward = FILENAME == backcheck
+	if (!!zone_cc[$3] == backward) {
+	    shouldbe = backward ? "a continental file" : "'backward'"
+	    printf "%s:%d: %s: Link should be in %s\n", \
+		FILENAME, FNR, $3, shouldbe
+	    status = 1
+	}
+	if (!backward && $2 != last_zone) {
+	    printf "%s:%d: Link %s should come just after Zone %s\n", \
+		FILENAME, FNR, $3, $2
+	    status = 1
+	}
+    }
     used[$2] = 1
     defined[$3] = $2
 }
diff --git a/etcetera b/etcetera
index a7e0eb4..865a220 100644
--- a/etcetera
+++ b/etcetera
@@ -16,26 +16,23 @@
 # Do not use a POSIX TZ setting like TZ='GMT+4', which is four hours
 # behind GMT but uses the completely misleading abbreviation "GMT".
 
-Zone	Etc/GMT		0	-	GMT
-
 # The following zone is used by tzcode functions like gmtime,
 # which load the "UTC" file to handle seconds properly.
 Zone	Etc/UTC		0	-	UTC
 
+# Functions like gmtime load the "GMT" file to handle leap seconds properly.
+# Vanguard section, which works with most .zi parsers.
+#Zone	GMT		0	-	GMT
+# Rearguard section, for TZUpdater 2.3.2 and earlier.
+Zone	Etc/GMT		0	-	GMT
+
 # The following link uses older naming conventions,
 # but it belongs here, not in the file 'backward',
 # as it is needed for tzcode releases through 2022a,
 # where functions like gmtime load "GMT" instead of the "Etc/UTC".
 # We want this to work even on installations that omit 'backward'.
 Link	Etc/GMT				GMT
-
-Link	Etc/UTC				Etc/Universal
-Link	Etc/UTC				Etc/Zulu
-
-Link	Etc/GMT				Etc/Greenwich
-Link	Etc/GMT				Etc/GMT-0
-Link	Etc/GMT				Etc/GMT+0
-Link	Etc/GMT				Etc/GMT0
+# End of rearguard section.
 
 # Be consistent with POSIX TZ settings in the Zone names,
 # even though this is the opposite of what many people expect.
diff --git a/europe b/europe
index bb0c7cf..76b741b 100644
--- a/europe
+++ b/europe
@@ -3734,7 +3734,6 @@ Zone	Europe/Istanbul	1:55:52 -	LMT	1880
 			2:00	1:00	EEST	2015 Nov  8  1:00u
 			2:00	EU	EE%sT	2016 Sep  7
 			3:00	-	+03
-Link	Europe/Istanbul	Asia/Istanbul	# Istanbul is in both continents.
 
 # Ukraine
 #
diff --git a/theory.html b/theory.html
index 56390ae..298db86 100644
--- a/theory.html
+++ b/theory.html
@@ -329,6 +329,7 @@ still supported.
 These legacy names are mostly defined in the file
 '<code>etcetera</code>'.
 Also, the file '<code>backward</code>' defines the legacy names
+'<code>Etc/GMT0</code>', '<code>Etc/GMT-0</code>', '<code>Etc/GMT+0</code>',
 '<code>GMT0</code>', '<code>GMT-0</code>' and '<code>GMT+0</code>',
 and the file '<code>northamerica</code>' defines the legacy names
 '<code>EST5EDT</code>', '<code>CST6CDT</code>',
diff --git a/zdump.c b/zdump.c
index a63a343..ef6cb8b 100644
--- a/zdump.c
+++ b/zdump.c
@@ -281,9 +281,9 @@ gmtzinit(void)
   if (USE_LOCALTIME_RZ) {
     /* 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"
+       the "Zone GMT 0 - 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
+       "Link 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
diff --git a/ziguard.awk b/ziguard.awk
index 0556cc4..a864f9f 100644
--- a/ziguard.awk
+++ b/ziguard.awk
@@ -15,6 +15,9 @@
 # after main became rearguard and vanguard became main).
 # There is no need to convert rearguard to other forms.
 #
+# When converting to vanguard form, the output can use the line
+# "Zone GMT 0 - GMT" which TZUpdater 2.3.2 mistakenly rejects.
+#
 # When converting to vanguard form, the output can use negative SAVE
 # values.
 #
@@ -151,6 +154,17 @@ DATAFORM != "main" {
     }
   }
 
+  # In vanguard form, use the line "Zone GMT 0 - GMT" instead of
+  # "Zone Etc/GMT 0 - GMT" and adjust Link lines accordingly.
+  # This works around a bug in TZUpdater 2.3.2.
+  if (/^#?(Zone|Link)[\t ]+(Etc\/)?GMT[\t ]/) {
+    if (($2 == "GMT") == (DATAFORM == "vanguard")) {
+      uncomment = in_comment
+    } else {
+      comment_out = !in_comment
+    }
+  }
+
   if (uncomment) {
     sub(/^#/, "")
   }
-- 
2.37.3



More information about the tz mailing list