Skip to content

Commit

Permalink
Simplify leap second updating logic
Browse files Browse the repository at this point in the history
Replace the Perl based "update-tai-utc.pl" script with a simple
Raku script called "add-leap-second.raku" that will take the date
for which a leap second should be added, and an optional source-
file to read.  This source-file will then be searched for markers
and the new leap second will be added at the appropriate place.

The new source-file is written to STDOUT.  An example adding a
leap second for 1 January 2021:

    $ tools/add-leap-second.raku 2021-01-01 >foo
    $ mv foo src/core.c/Rakudo/Internals.pm
    $ git diff
    @@ -811,6 +811,7 @@ implementation detail and has no serviceable parts inside"
             '2012-06-30',
             '2015-06-30',
             '2016-12-31',
    +        '2020-12-31',
             #END leap-second-dates
          );

    @@ -856,6 +857,7 @@ implementation detail and has no serviceable parts inside"
             1341100800,
             1435708800,
             1483228800,
    +        1609459200,
             #END leap-second-posix
  • Loading branch information
lizmat committed Jan 27, 2020
1 parent 5d65764 commit 25c84b3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/core.c/Rakudo/Internals.pm6
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions 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;
}
}
47 changes: 0 additions & 47 deletions tools/update-tai-utc.pl

This file was deleted.

0 comments on commit 25c84b3

Please sign in to comment.