2 # zoneinfo2lua.pl - Make Lua module from /usr/share/zoneinfo
3 # Execute from within /usr/share/zoneinfo
9 my $tzdir = $ARGV[0] || "/usr/share/zoneinfo";
11 chdir($tzdir) || die "chdir($tzdir): $!\n";
14 open( ZTAB, "< ./zone.tab" ) || die "Unable to open 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, "< ./$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 "Unable to open $zone: $!\n";
52 LuCI - Autogenerated Zoneinfo Module
54 Licensed under the Apache License, Version 2.0 (the "License");
55 you may not use this file except in compliance with the License.
56 You may obtain a copy of the License at
58 http://www.apache.org/licenses/LICENSE-2.0
62 module "luci.sys.zoneinfo"
67 foreach my $zone ( sort keys %TZ ) {
68 printf "\t{ '%s', '%s' },\n", $zone, $TZ{$zone}
78 foreach my $tz ( sort keys %TZ ) {
84 ( -? \d+ (?: : \d+ )? )
87 ( -? \d+ (?: : \d+ )? )?
91 my ( $offset, $s, $h, $m ) = ( 0, 1, 0, 0 );
92 my ( $std, $soffset, $dst, $doffset ) = ( $1, $2, $3, $4 );
94 next if $seen{$std}; # and ( !$dst or $seen{$dst} );
97 ( $s, $h, $m ) = $soffset =~ /^(-)?(\d+)(?::(\d+))?$/;
103 $offset = $s * $h * 60 * 60;
104 $offset += $s * $m * 60;
106 printf("\t%-5s = %6d,\t-- %s\n",
107 lc($std), $offset, $std);
113 ( $s, $h, $m ) = $doffset =~ /^(-)?(\d+)(?::(\d+))?$/;
119 $offset = $s * $h * 60 * 60;
120 $offset += $s * $m * 60;
125 printf("\t%-5s = %6d,\t-- %s\n",
126 lc($dst), $offset, $dst);
132 printf("\t%-5s = %6d,\t-- %s\n",
133 lc($std), $offset, $std);