1 package DateTime::LeapSecond;
8 use vars qw( $VERSION );
9 use vars qw( @RD @LEAP_SECONDS %RD_LENGTH );
11 $VERSION = '0.05'; # last standalone distro was 0.03
15 # Generates a Perl binary decision tree
17 my ($beg, $end, $tab, $op) = @_;
18 my $step = int(($end - $beg) / 2);
21 $tmp = "${tab}return $LEAP_SECONDS[$beg + 1];\n";
24 $tmp = "${tab}if (\$val < " . $RD[$beg + $step] . ") {\n";
25 $tmp .= _make_utx ($beg, $beg + $step, $tab . " ", $op);
27 $tmp .= "${tab}else {\n";
28 $tmp .= _make_utx ($beg + $step, $end, $tab . " ", $op);
33 # Process BEGIN data and write binary tree decision table
37 my ( $year, $mon, $mday, $leap_seconds ) =
38 ( shift, shift, shift, shift );
39 # print "$year,$mon,$mday\n";
41 my $utc_epoch = DateTime->_ymd2rd( $year, ( $mon =~ /Jan/i ? 1 : 7 ), $mday );
44 push @LEAP_SECONDS, $value;
47 $RD_LENGTH{ $utc_epoch - 1 } = $leap_seconds;
49 # warn "$year,$mon,$mday = $utc_epoch +$value";
52 push @LEAP_SECONDS, ++$value;
56 # write binary tree decision table
58 $tmp = "sub leap_seconds {\n";
59 $tmp .= " my \$val = shift;\n";
60 $tmp .= _make_utx (-1, 1 + $#RD, " ", "+");
63 # NOTE: uncomment the line below to see the code:
71 exists $RD_LENGTH{ $_[0] } ? $RD_LENGTH{ $_[0] } : 0
75 exists $RD_LENGTH{ $_[0] } ? 86400 + $RD_LENGTH{ $_[0] } : 86400
79 # this table: ftp://62.161.69.5/pub/tai/publication/leaptab.txt
80 # known accurate until (at least): 2005-12-31
82 # There are no leap seconds before 1972, because that's the
83 # year this system was implemented.
85 # year month day number-of-leapseconds
115 __PACKAGE__->_initialize();
122 DateTime::LeapSecond - leap seconds table and utilities
127 use DateTime::LeapSecond;
129 print "Leap seconds between years 1990 and 2000 are ";
130 print Date::Leapsecond::leap_seconds( $utc_rd_2000 ) -
131 Date::Leapsecond::leap_seconds( $utc_rd_1990 );
135 This module is used to calculate leap seconds for a given Rata Die
136 day. It is used when DateTime.pm cannot compile the XS version of
139 This library is known to be accurate for dates until December 2009.
141 There are no leap seconds before 1972, because that's the year this
142 system was implemented.
146 =item * leap_seconds( $rd )
148 Returns the number of accumulated leap seconds for a given day,
149 in the range 0 .. 22.
151 =item * extra_seconds( $rd )
153 Returns the number of leap seconds for a given day,
154 in the range -2 .. 2.
156 =item * day_length( $rd )
158 Returns the number of seconds for a given day,
159 in the range 86398 .. 86402.
165 Flávio Soibelmann Glock, E<lt>fglock@pucrs.brE<gt>
169 Copyright (c) 2003 Flávio Soibelmann Glock. Copyright (c) 2004-2009
170 David Rolsky. All rights reserved. This program is free software;
171 you can redistribute it and/or modify it under the same terms as Perl
174 The full text of the license can be found in the LICENSE file included
179 E<lt>http://hpiers.obspm.fr/eop-pc/earthor/utc/leapsecond.htmlE<gt>
181 http://datetime.perl.org