]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/tzdata/ziguard.awk
Update timezone database information.
[FreeBSD/FreeBSD.git] / contrib / tzdata / ziguard.awk
1 # Convert tzdata source into vanguard or rearguard form.
2
3 # Contributed by Paul Eggert.  This file is in the public domain.
4
5 # This is not a general-purpose converter; it is designed for current tzdata.
6 # It just converts from current source to main, vanguard, and rearguard forms.
7 # Although it might be nice for it to be idempotent, or to be useful
8 # for converting back and forth between vanguard and rearguard formats,
9 # it does not do these nonessential tasks now.
10 #
11 # Although main and vanguard forms are currently equivalent,
12 # this need not always be the case.
13 #
14 # When converting to vanguard form, the output can use negative SAVE
15 # values.
16 #
17 # When converting to rearguard form, the output uses only nonnegative
18 # SAVE values.  The idea is for the output data to simulate the behavior
19 # of the input data as best it can within the constraints of the
20 # rearguard format.
21
22 BEGIN {
23   dataform_type["vanguard"] = 1
24   dataform_type["main"] = 1
25   dataform_type["rearguard"] = 1
26
27   # The command line should set DATAFORM.
28   if (!dataform_type[DATAFORM]) exit 1
29   vanguard = DATAFORM == "vanguard"
30 }
31
32 /^Zone/ { zone = $2 }
33
34 DATAFORM != "main" {
35   in_comment = /^#/
36   uncomment = comment_out = 0
37
38   # If this line should differ due to Czechoslovakia using negative SAVE values,
39   # uncomment the desired version and comment out the undesired one.
40   if (zone == "Europe/Prague" && /1947 Feb 23/) {
41     if (($(in_comment + 2) != "-") == vanguard) {
42       uncomment = in_comment
43     } else {
44       comment_out = !in_comment
45     }
46   }
47
48   # If this line should differ due to Ireland using negative SAVE values,
49   # uncomment the desired version and comment out the undesired one.
50   Rule_Eire = /^#?Rule[\t ]+Eire[\t ]/
51   Zone_Dublin_post_1968 \
52     = (zone == "Europe/Dublin" && /^#?[\t ]+[01]:00[\t ]/ \
53        && (!$(in_comment + 4) || 1968 < $(in_comment + 4)))
54   if (Rule_Eire || Zone_Dublin_post_1968) {
55     if ((Rule_Eire \
56          || (Zone_Dublin_post_1968 && $(in_comment + 3) == "IST/GMT"))  \
57         == vanguard) {
58       uncomment = in_comment
59     } else {
60       comment_out = !in_comment
61     }
62   }
63
64   # If this line should differ due to Namibia using negative SAVE values,
65   # uncomment the desired version and comment out the undesired one.
66   Rule_Namibia = /^#?Rule[\t ]+Namibia[\t ]/
67   Zone_using_Namibia_rule \
68     = (zone == "Africa/Windhoek" \
69        && ($(in_comment + 2) == "Namibia" \
70            || (1994 <= $(in_comment + 4) && $(in_comment + 4) <= 2017) \
71            || in_comment + 3 == NF))
72   if (Rule_Namibia || Zone_using_Namibia_rule) {
73       if ((Rule_Namibia \
74            ? ($(in_comment + 9) ~ /^-/ \
75               || ($(in_comment + 9) == 0 && $(in_comment + 10) == "CAT")) \
76            : $(in_comment + 1) == "2:00" && $(in_comment + 2) == "Namibia") \
77           == vanguard) {
78       uncomment = in_comment
79     } else {
80       comment_out = !in_comment
81     }
82   }
83
84   if (uncomment) {
85     sub(/^#/, "")
86   }
87   if (comment_out) {
88     sub(/^/, "#")
89   }
90
91   # In rearguard format, change the Japan rule line with "Sat>=8 25:00"
92   # to "Sun>=9 1:00", to cater to zic before 2007 and to older Java.
93   if (!vanguard && $1 == "Rule" && $7 == "Sat>=8" && $8 == "25:00") {
94     sub(/Sat>=8/, "Sun>=9")
95     sub(/25:00/, " 1:00")
96   }
97
98   # In rearguard format, change the Morocco lines with negative SAVE values
99   # to use positive SAVE values.
100   if (!vanguard && $1 == "Rule" && $2 == "Morocco" && $4 == 2018 \
101       && $6 == "Oct") {
102     sub(/\t2018\t/, "\t2017\t")
103   }
104   if (!vanguard && $1 == "Rule" && $2 == "Morocco" && 2019 <= $3) {
105     if ($9 == "0") {
106       sub(/\t0\t/, "\t1:00\t")
107     } else {
108       sub(/\t-1:00\t/, "\t0\t")
109     }
110   }
111   if (!vanguard && $1 == "1:00" && $2 == "Morocco" && $3 == "+01/+00") {
112     sub(/1:00\tMorocco\t\+01\/\+00$/, "0:00\tMorocco\t+00/+01")
113   }
114 }
115
116 # If a Link line is followed by a Zone line for the same data, comment
117 # out the Link line.  This can happen if backzone overrides a Link
118 # with a Zone.
119 /^Link/ {
120   linkline[$3] = NR
121 }
122 /^Zone/ {
123   sub(/^Link/, "#Link", line[linkline[$2]])
124 }
125
126 { line[NR] = $0 }
127
128 END {
129   for (i = 1; i <= NR; i++)
130     print line[i]
131 }