2 # zoneinfo2lua.pl - Make Lua module from /usr/share/zoneinfo
3 # Execute from within root of Luci feed, usually feeds/luci
6 # NOTE: Darwin before 13.6.4 (22G513) may have had bugs in some TZinfo2 files.
7 # Some lacked the mandatory footers detailed in RFC 8536. A complete tzdata can
8 # not be built when this script is run on Darwin 13.6.3 and possibly other
9 # Darwin versions released prior to 13.6.4 (e.g. even Darwin (Sonoma) 14.2.1).
15 my $tzdin = $ARGV[0] || "/usr/share/zoneinfo";
16 my $tzdout = $ARGV[1] || "./modules/luci-base/luasrc/sys/zoneinfo";
19 open( ZTAB
, "< $tzdin/zone.tab" ) || die "open($tzdin/zone.tab): $!";
22 chomp( my $line = readline ZTAB
);
23 next if $line =~ /^#/ || $line =~ /^\s+$/;
25 my ( undef, undef, $zone, @comment ) = split /\s+/, $line;
27 printf STDERR
"%-40s", $zone;
29 if( open ZONE
, "< $tzdin/$zone" ) {
32 while( tell(ZONE
) > 0 ) {
33 read ZONE
, my $char, 1;
34 ( $char eq "\012" ) ?
last : seek ZONE
, -2, 1;
37 chomp( my $tz = readline ZONE
);
38 print STDERR
( $tz || "(no tzinfo found)" ), "\n";
48 print STDERR
"open($tzdin/$zone): $!\n";
54 # Add Etc/GMT zones from manually as they are not in zone.tab
55 $TZ{"Etc/GMT"} = "GMT0";
56 $TZ{"Etc/GMT-1"} = "<+01>-1";
57 $TZ{"Etc/GMT-2"} = "<+02>-2";
58 $TZ{"Etc/GMT-3"} = "<+03>-3";
59 $TZ{"Etc/GMT-4"} = "<+04>-4";
60 $TZ{"Etc/GMT-5"} = "<+05>-5";
61 $TZ{"Etc/GMT-6"} = "<+06>-6";
62 $TZ{"Etc/GMT-7"} = "<+07>-7";
63 $TZ{"Etc/GMT-8"} = "<+08>-8";
64 $TZ{"Etc/GMT-9"} = "<+09>-9";
65 $TZ{"Etc/GMT-10"} = "<+10>-10";
66 $TZ{"Etc/GMT-11"} = "<+11>-11";
67 $TZ{"Etc/GMT-12"} = "<+12>-12";
68 $TZ{"Etc/GMT-13"} = "<+13>-13";
69 $TZ{"Etc/GMT-14"} = "<+14>-14";
70 $TZ{"Etc/GMT+1"} = "<-01>1";
71 $TZ{"Etc/GMT+2"} = "<-02>2";
72 $TZ{"Etc/GMT+3"} = "<-03>3";
73 $TZ{"Etc/GMT+4"} = "<-04>4";
74 $TZ{"Etc/GMT+5"} = "<-05>5";
75 $TZ{"Etc/GMT+6"} = "<-06>6";
76 $TZ{"Etc/GMT+7"} = "<-07>7";
77 $TZ{"Etc/GMT+8"} = "<-08>8";
78 $TZ{"Etc/GMT+9"} = "<-09>9";
79 $TZ{"Etc/GMT+10"} = "<-10>10";
80 $TZ{"Etc/GMT+11"} = "<-11>11";
81 $TZ{"Etc/GMT+12"} = "<-12>12";
83 open(O
, "> $tzdout/tzdata.lua") || die "open($tzdout/tzdata.lua): $!\n";
85 print STDERR
"Writing time zones to $tzdout/tzdata.lua ... ";
87 -- Licensed to the public under the Apache License 2.0.
89 module "luci.sys.zoneinfo.tzdata"
94 foreach my $zone ( sort keys %TZ ) {
95 printf O
"\t{ '%s', '%s' },\n", $zone, $TZ{$zone}
101 print STDERR
"done\n";
104 open (O
, "> $tzdout/tzoffset.lua") || die "open($tzdout/tzoffset.lua): $!\n";
106 print STDERR
"Writing time offsets to $tzdout/tzoffset.lua ... ";
108 -- Licensed to the public under the Apache License 2.0.
110 module "luci.sys.zoneinfo.tzoffset"
116 foreach my $tz ( sort keys %TZ ) {
122 ( -? \d
+ (?
: : \d
+ )?
)
125 ( -? \d
+ (?
: : \d
+ )?
)?
129 my ( $offset, $s, $h, $m ) = ( 0, 1, 0, 0 );
130 my ( $std, $soffset, $dst, $doffset ) = ( $1, $2, $3, $4 );
132 next if $seen{$std}; # and ( !$dst or $seen{$dst} );
135 ( $s, $h, $m ) = $soffset =~ /^(-)?(\d+)(?::(\d+))?$/;
141 $offset = $s * $h * 60 * 60;
142 $offset += $s * $m * 60;
144 printf O
"\t%-5s = %6d,\t-- %s\n",
145 lc($std), $offset, $std;
151 ( $s, $h, $m ) = $doffset =~ /^(-)?(\d+)(?::(\d+))?$/;
157 $offset = $s * $h * 60 * 60;
158 $offset += $s * $m * 60;
163 printf O
"\t%-5s = %6d,\t-- %s\n",
164 lc($dst), $offset, $dst;
170 printf O
"\t%-5s = %6d,\t-- %s\n",
171 lc($std), $offset, $std;
182 print STDERR
"done\n";