diff --git a/src/core.c/Rakudo/Internals.pm6 b/src/core.c/Rakudo/Internals.pm6 index c326c56f2ab..45ba646b1a2 100644 --- a/src/core.c/Rakudo/Internals.pm6 +++ b/src/core.c/Rakudo/Internals.pm6 @@ -768,7 +768,7 @@ implementation detail and has no serviceable parts inside" } # Keep track of the differences between TAI and UTC for internal use. -# The "BEGIN" and "END" comments are for tools/update-tai-utc.pl. +# The "BEGIN" and "END" comments are for tools/add-leap-second.raku. # # Some handy tables: # http://tf.nist.gov/pubs/bulletin/leapsecond.htm diff --git a/tools/add-leap-second.raku b/tools/add-leap-second.raku new file mode 100755 index 00000000000..9fbd147e032 --- /dev/null +++ b/tools/add-leap-second.raku @@ -0,0 +1,34 @@ +#!raku + +# This helper script is intended to make adding leap seconds to the +# Raku system as easy as possible: by just giving the date for which +# to add the leap second, it will scan the file for current leap +# second information and add leap second information for that date +# to the source, which is output to STDOUT. After inspection one +# can then just overwrite the source-file and a re-compilation +# of the setting should then be enough to activate the new leap +# second in Raku's time logic. + +use v6.c; + +sub MAIN( + #| the date for which to add a leap second + Str $the-date, + #| the source file containing leap second logic (default: src/core.c/Rakudo/Internals.pm6) + $from = 'src/core.c/Rakudo/Internals.pm6' +) { + + # set up the new leap second info + my $date = Date.new($the-date); + my $epoch = $date.DateTime.posix; + my $before = $date.earlier(:1day); + + # run through the source file and update as appropriate + for $from.IO.lines -> $line { + say " '$before'," + if $line eq ' #END leap-second-dates'; + say " $epoch," + if $line eq ' #END leap-second-posix'; + say $line; + } +} diff --git a/tools/update-tai-utc.pl b/tools/update-tai-utc.pl deleted file mode 100755 index 74cdb9927cf..00000000000 --- a/tools/update-tai-utc.pl +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/perl -# Updates src/core/tai-utc.pm6. - -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] ||= 'src/core/Rakudo/Internals.pm6'; -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';