2 # zoneinfo2lua.pl - Make Lua module from /usr/share/zoneinfo
3 # Execute from within root of Luci feed, usually feeds/luci
10 my $tzdin = $ARGV[0] || "/usr/share/zoneinfo";
11 my $tzdout = $ARGV[1] || "./modules/luci-base/luasrc/sys/zoneinfo";
14 open( ZTAB, "< $tzdin/zone.tab" ) || die "open($tzdin/zone.tab): $!";
17 chomp( my $line = readline ZTAB );
18 next if $line =~ /^#/ || $line =~ /^\s+$/;
20 my ( undef, undef, $zone, @comment ) = split /\s+/, $line;
22 printf STDERR "%-40s", $zone;
24 if( open ZONE, "< $tzdin/$zone" ) {
27 while( tell(ZONE) > 0 ) {
28 read ZONE, my $char, 1;
29 ( $char eq "\012" ) ? last : seek ZONE, -2, 1;
32 chomp( my $tz = readline ZONE );
33 print STDERR ( $tz || "(no tzinfo found)" ), "\n";
43 print STDERR "open($tzdin/$zone): $!\n";
49 # Add Etc/GMT zones from manually as they are not in zone.tab
50 $TZ{"Etc/GMT"} = "GMT0";
51 $TZ{"Etc/GMT-1"} = "<+01>-1";
52 $TZ{"Etc/GMT-2"} = "<+02>-2";
53 $TZ{"Etc/GMT-3"} = "<+03>-3";
54 $TZ{"Etc/GMT-4"} = "<+04>-4";
55 $TZ{"Etc/GMT-5"} = "<+05>-5";
56 $TZ{"Etc/GMT-6"} = "<+06>-6";
57 $TZ{"Etc/GMT-7"} = "<+07>-7";
58 $TZ{"Etc/GMT-8"} = "<+08>-8";
59 $TZ{"Etc/GMT-9"} = "<+09>-9";
60 $TZ{"Etc/GMT-10"} = "<+10>-10";
61 $TZ{"Etc/GMT-11"} = "<+11>-11";
62 $TZ{"Etc/GMT-12"} = "<+12>-12";
63 $TZ{"Etc/GMT-13"} = "<+13>-13";
64 $TZ{"Etc/GMT-14"} = "<+14>-14";
65 $TZ{"Etc/GMT+1"} = "<-01>1";
66 $TZ{"Etc/GMT+2"} = "<-02>2";
67 $TZ{"Etc/GMT+3"} = "<-03>3";
68 $TZ{"Etc/GMT+4"} = "<-04>4";
69 $TZ{"Etc/GMT+5"} = "<-05>5";
70 $TZ{"Etc/GMT+6"} = "<-06>6";
71 $TZ{"Etc/GMT+7"} = "<-07>7";
72 $TZ{"Etc/GMT+8"} = "<-08>8";
73 $TZ{"Etc/GMT+9"} = "<-09>9";
74 $TZ{"Etc/GMT+10"} = "<-10>10";
75 $TZ{"Etc/GMT+11"} = "<-11>11";
76 $TZ{"Etc/GMT+12"} = "<-12>12";
78 open(O, "> $tzdout/tzdata.lua") || die "open($tzdout/tzdata.lua): $!\n";
80 print STDERR "Writing time zones to $tzdout/tzdata.lua ... ";
82 -- Licensed to the public under the Apache License 2.0.
84 module "luci.sys.zoneinfo.tzdata"
89 foreach my $zone ( sort keys %TZ ) {
90 printf O "\t{ '%s', '%s' },\n", $zone, $TZ{$zone}
96 print STDERR "done\n";
99 open (O, "> $tzdout/tzoffset.lua") || die "open($tzdout/tzoffset.lua): $!\n";
101 print STDERR "Writing time offsets to $tzdout/tzoffset.lua ... ";
103 -- Licensed to the public under the Apache License 2.0.
105 module "luci.sys.zoneinfo.tzoffset"
111 foreach my $tz ( sort keys %TZ ) {
117 ( -? \d+ (?: : \d+ )? )
120 ( -? \d+ (?: : \d+ )? )?
124 my ( $offset, $s, $h, $m ) = ( 0, 1, 0, 0 );
125 my ( $std, $soffset, $dst, $doffset ) = ( $1, $2, $3, $4 );
127 next if $seen{$std}; # and ( !$dst or $seen{$dst} );
130 ( $s, $h, $m ) = $soffset =~ /^(-)?(\d+)(?::(\d+))?$/;
136 $offset = $s * $h * 60 * 60;
137 $offset += $s * $m * 60;
139 printf O "\t%-5s = %6d,\t-- %s\n",
140 lc($std), $offset, $std;
146 ( $s, $h, $m ) = $doffset =~ /^(-)?(\d+)(?::(\d+))?$/;
152 $offset = $s * $h * 60 * 60;
153 $offset += $s * $m * 60;
158 printf O "\t%-5s = %6d,\t-- %s\n",
159 lc($dst), $offset, $dst;
165 printf O "\t%-5s = %6d,\t-- %s\n",
166 lc($std), $offset, $std;
177 print STDERR "done\n";