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";
50 open(O, "> $tzdout/tzdata.lua") || die "open($tzdout/tzdata.lua): $!\n";
52 print STDERR "Writing time zones to $tzdout/tzdata.lua ... ";
54 -- Licensed to the public under the Apache License 2.0.
56 module "luci.sys.zoneinfo.tzdata"
61 foreach my $zone ( sort keys %TZ ) {
62 printf O "\t{ '%s', '%s' },\n", $zone, $TZ{$zone}
68 print STDERR "done\n";
71 open (O, "> $tzdout/tzoffset.lua") || die "open($tzdout/tzoffset.lua): $!\n";
73 print STDERR "Writing time offsets to $tzdout/tzoffset.lua ... ";
75 -- Licensed to the public under the Apache License 2.0.
77 module "luci.sys.zoneinfo.tzoffset"
83 foreach my $tz ( sort keys %TZ ) {
89 ( -? \d+ (?: : \d+ )? )
92 ( -? \d+ (?: : \d+ )? )?
96 my ( $offset, $s, $h, $m ) = ( 0, 1, 0, 0 );
97 my ( $std, $soffset, $dst, $doffset ) = ( $1, $2, $3, $4 );
99 next if $seen{$std}; # and ( !$dst or $seen{$dst} );
102 ( $s, $h, $m ) = $soffset =~ /^(-)?(\d+)(?::(\d+))?$/;
108 $offset = $s * $h * 60 * 60;
109 $offset += $s * $m * 60;
111 printf O "\t%-5s = %6d,\t-- %s\n",
112 lc($std), $offset, $std;
118 ( $s, $h, $m ) = $doffset =~ /^(-)?(\d+)(?::(\d+))?$/;
124 $offset = $s * $h * 60 * 60;
125 $offset += $s * $m * 60;
130 printf O "\t%-5s = %6d,\t-- %s\n",
131 lc($dst), $offset, $dst;
137 printf O "\t%-5s = %6d,\t-- %s\n",
138 lc($std), $offset, $std;
149 print STDERR "done\n";