Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added a Perl 5 script to update the leap-second tables in tai-utc.pm.
I tried to do it in Perl 6 first, but I couldn't get perl6-lwp-simple to work.
- Loading branch information
Kodi Arfer
authored and
Kodi Arfer
committed
Jan 2, 2011
1 parent
db11af9
commit fc2db18
Showing
2 changed files
with
76 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #!/usr/bin/perl | ||
| # Updates src/core/tai-utc.pm. | ||
|
|
||
| use warnings; | ||
| use strict; | ||
| use Time::y2038 'timegm'; | ||
| use File::Slurp qw(slurp write_file); | ||
| use LWP::Simple 'get'; | ||
|
|
||
| my $url = 'ftp://hpiers.obspm.fr/iers/bul/bulc/TimeSteps.history'; | ||
|
|
||
| $ARGV[0] or die "Please provide a path to src/core/tai-utc.pm.\n"; | ||
| my $tu_path = $ARGV[0]; | ||
|
|
||
| my @dates = do { | ||
| my @lines = split /\n/, get $url; | ||
| pop @lines; | ||
| shift @lines until $lines[0] =~ /\A 1972 Jul\. 1/; | ||
| map { | ||
| /(\d{4}) (Jan|Jul)/; | ||
| $2 eq 'Jan' ? [$1 - 1, 12, 31] : [$1, 6, 30] | ||
| } @lines | ||
| }; | ||
|
|
||
| my $tu = slurp $tu_path; | ||
| sub replace { | ||
| my ($find, $fmt, $f) = @_; | ||
| $tu =~ s | ||
| {^( *)#BEGIN $find\n.+?^ *#END $find\n} | ||
| { sprintf "$1#BEGIN $find\n%s\n$1#END $find\n", join "\n", | ||
| map { sprintf "%s$fmt", $1, $f->(@$_) } @dates }ems | ||
| or die "Couldn't replace $find"; | ||
| } | ||
| replace 'leap-second-dates', '%d-%02d-%02d', sub { @_ }; | ||
| replace 'leap-second-posix', '%10d', sub { | ||
| my ($y, $m, $d) = @_; | ||
| 1 + timegm 59, 59, 23, $d, $m - 1, $y - 1900; | ||
| }; | ||
| write_file $tu_path, $tu; | ||
| print "Updated.\n"; | ||
|
|
||
| # The IERS announces midyear leap seconds in early January and | ||
| # end-of-year leap seconds in early July. So: | ||
|
|
||
| my $month = (gmtime)[4]; | ||
| printf "This program should next be run in %s.\n", | ||
| 1 < $month && $month < 8 ? 'August' : 'February'; |