diff options
| author | Jo-Philipp Wich | 2022-09-10 11:59:59 +0000 |
|---|---|---|
| committer | Jo-Philipp Wich | 2022-10-24 23:03:37 +0000 |
| commit | f2133059e1d6695e6a1b572ae6aded9d7dd3db35 (patch) | |
| tree | a9bafa26a0f230a613d2150812132497c4a1498e | |
| parent | e0650da41e17d9e9006b29e726a2b2e8b7410f66 (diff) | |
| download | luci-f2133059e1d6695e6a1b572ae6aded9d7dd3db35.tar.gz | |
build: add zoneinfo2ucode.pl
Add a zoneinfo2ucode.pl script which is the ucode equivalent to
zoneinfo2lua.pl. It will generate a ucode module exporting a dictionary
of known timezone names and their corresponding TZ strings.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
| -rwxr-xr-x | build/zoneinfo2ucode.pl | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/build/zoneinfo2ucode.pl b/build/zoneinfo2ucode.pl new file mode 100755 index 0000000000..35dfac3797 --- /dev/null +++ b/build/zoneinfo2ucode.pl @@ -0,0 +1,93 @@ +#!/usr/bin/perl +# zoneinfo2ucode.pl - Make ucode module from /usr/share/zoneinfo +# Execute from within root of Luci feed, usually feeds/luci + +use strict; + +my %TZ; + +my $tzdin = $ARGV[0] || "/usr/share/zoneinfo"; +my $tzdout = $ARGV[1] || "./modules/luci-base-ucode/ucode/zoneinfo.uc"; + +local $/ = "\012"; +open( ZTAB, "< $tzdin/zone.tab" ) || die "open($tzdin/zone.tab): $!"; + +while( ! eof ZTAB ) { + chomp( my $line = readline ZTAB ); + next if $line =~ /^#/ || $line =~ /^\s+$/; + + my ( undef, undef, $zone, @comment ) = split /\s+/, $line; + + printf STDERR "%-40s", $zone; + + if( open ZONE, "< $tzdin/$zone" ) { + seek ZONE, -2, 2; + + while( tell(ZONE) > 0 ) { + read ZONE, my $char, 1; + ( $char eq "\012" ) ? last : seek ZONE, -2, 1; + } + + chomp( my $tz = readline ZONE ); + print STDERR ( $tz || "(no tzinfo found)" ), "\n"; + close ZONE; + + if( $tz ) { + $zone =~ s/_/ /g; + $TZ{$zone} = $tz; + } + } + else + { + print STDERR "open($tzdin/$zone): $!\n"; + } +} + +close ZTAB; + +# Add Etc/GMT zones from manually as they are not in zone.tab +$TZ{"Etc/GMT"} = "GMT0"; +$TZ{"Etc/GMT-1"} = "<+01>-1"; +$TZ{"Etc/GMT-2"} = "<+02>-2"; +$TZ{"Etc/GMT-3"} = "<+03>-3"; +$TZ{"Etc/GMT-4"} = "<+04>-4"; +$TZ{"Etc/GMT-5"} = "<+05>-5"; +$TZ{"Etc/GMT-6"} = "<+06>-6"; +$TZ{"Etc/GMT-7"} = "<+07>-7"; +$TZ{"Etc/GMT-8"} = "<+08>-8"; +$TZ{"Etc/GMT-9"} = "<+09>-9"; +$TZ{"Etc/GMT-10"} = "<+10>-10"; +$TZ{"Etc/GMT-11"} = "<+11>-11"; +$TZ{"Etc/GMT-12"} = "<+12>-12"; +$TZ{"Etc/GMT-13"} = "<+13>-13"; +$TZ{"Etc/GMT-14"} = "<+14>-14"; +$TZ{"Etc/GMT+1"} = "<-01>1"; +$TZ{"Etc/GMT+2"} = "<-02>2"; +$TZ{"Etc/GMT+3"} = "<-03>3"; +$TZ{"Etc/GMT+4"} = "<-04>4"; +$TZ{"Etc/GMT+5"} = "<-05>5"; +$TZ{"Etc/GMT+6"} = "<-06>6"; +$TZ{"Etc/GMT+7"} = "<-07>7"; +$TZ{"Etc/GMT+8"} = "<-08>8"; +$TZ{"Etc/GMT+9"} = "<-09>9"; +$TZ{"Etc/GMT+10"} = "<-10>10"; +$TZ{"Etc/GMT+11"} = "<-11>11"; +$TZ{"Etc/GMT+12"} = "<-12>12"; + +open(O, "> $tzdout") || die "open($tzdout): $!\n"; + +print STDERR "Writing time zones to $tzdout ... "; +print O <<HEAD; +// Autogenerated by zoneinfo2ucode.pl + +export default { +HEAD + +foreach my $zone ( sort keys %TZ ) { + printf O "\t'%s': '%s',\n", $zone, $TZ{$zone} +} + +print O "};\n"; +close O; + +print STDERR "done\n"; |