2 # zoneinfo2lua.pl - Make Lua module from /usr/share/zoneinfo
3 # Execute from within /usr/share/zoneinfo
10 my $tzdin = $ARGV[0] || "/usr/share/zoneinfo";
11 my $tzdout = $ARGV[1] || "./libs/sys/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 ... ";
55 LuCI - Autogenerated Zoneinfo Module
57 Licensed under the Apache License, Version 2.0 (the "License");
58 you may not use this file except in compliance with the License.
59 You may obtain a copy of the License at
61 http://www.apache.org/licenses/LICENSE-2.0
65 module "luci.sys.zoneinfo.tzdata"
70 foreach my $zone ( sort keys %TZ ) {
71 printf O "\t{ '%s', '%s' },\n", $zone, $TZ{$zone}
77 print STDERR "done\n";
80 open (O, "> $tzdout/tzoffset.lua") || die "open($tzdout/tzoffset.lua): $!\n";
82 print STDERR "Writing time offsets to $tzdout/tzoffset.lua ... ";
85 LuCI - Autogenerated Zoneinfo Module
87 Licensed under the Apache License, Version 2.0 (the "License");
88 you may not use this file except in compliance with the License.
89 You may obtain a copy of the License at
91 http://www.apache.org/licenses/LICENSE-2.0
95 module "luci.sys.zoneinfo.tzoffset"
101 foreach my $tz ( sort keys %TZ ) {
107 ( -? \d+ (?: : \d+ )? )
110 ( -? \d+ (?: : \d+ )? )?
114 my ( $offset, $s, $h, $m ) = ( 0, 1, 0, 0 );
115 my ( $std, $soffset, $dst, $doffset ) = ( $1, $2, $3, $4 );
117 next if $seen{$std}; # and ( !$dst or $seen{$dst} );
120 ( $s, $h, $m ) = $soffset =~ /^(-)?(\d+)(?::(\d+))?$/;
126 $offset = $s * $h * 60 * 60;
127 $offset += $s * $m * 60;
129 printf O "\t%-5s = %6d,\t-- %s\n",
130 lc($std), $offset, $std;
136 ( $s, $h, $m ) = $doffset =~ /^(-)?(\d+)(?::(\d+))?$/;
142 $offset = $s * $h * 60 * 60;
143 $offset += $s * $m * 60;
148 printf O "\t%-5s = %6d,\t-- %s\n",
149 lc($dst), $offset, $dst;
155 printf O "\t%-5s = %6d,\t-- %s\n",
156 lc($std), $offset, $std;
167 print STDERR "done\n";