epoch to UTCstring conversion at leap-second boundary

[email protected] (Andrew Davis)
Newsgroups perl.datetime
Message-ID <[email protected]>
I need to obtain UTC date-time strings from an epoch input.
The UTC output needs to take leap-seconds into account.
I wrote this script to test things:

#!/usr/local/bin/perl

use strict;
use DateTime;
use DateTime::Format::Epoch;

my $dt = DateTime->new(year => 2008, month => 12, day => 31, 
time_zone => "UTC");
my $formatter = DateTime::Format::Epoch->new(
                       epoch          => $dt,
                       unit           => 'seconds',
                       type           => 'int',
                       skip_leap_seconds => 0,
                       start_at       => 0,
                       local_epoch    => undef,
         );

my $epoch = 86398;
for (my $ii=0; $ii<=4; $ii++) {
    my $dt2 = $formatter->parse_datetime( $epoch );
    print "$dt2\n";
    $epoch++;
}

Since there was a leap-second add at the end of 2008, I expected (wanted)
to get the following output:
2008-12-31T23:59:58
2008-12-31T23:59:59
2008-12-31T23:59:60
2009-01-01T00:00:00
2009-01-01T00:00:01

However, I got this error instead:
2008-12-31T23:59:58
2008-12-31T23:59:59
The 'hour' parameter ("24") to DateTime::new did not pass the 'an 
integer between 0 and 23' callback
  at 
/usr/local/lib/perl5/site_perl/5.10.0/i386-linux-thread-multi/DateTime.pm 
line 201
         DateTime::new(undef, 'hour', 24, 'minute', 0, 'second', 0, 
'month', 12, ...) called at 
/usr/local/lib/perl5/site_perl/5.10.0/i386-linux-thread-multi/DateTime.pm 
line 566
         DateTime::from_object(undef, 'object', 
'DateTime::Format::Epoch::_DateTime=HASH(0x89c98cc)') called at 
/usr/local/lib/perl5/site_perl/5.10.0/DateTime/Format/Epoch.pm line 180
         DateTime::Format::Epoch::parse_datetime('DateTime::Format::Epoch=HASH(0x892e5ac)', 
86400) called at ./testleap.pl line 19

If I set skip_leap_seconds to TRUE, I get no error, but the result is not
what I want:
2008-12-31T23:59:58
2008-12-31T23:59:59
2009-01-01T00:00:00
2009-01-01T00:00:01
2009-01-01T00:00:02

I'm hoping someone can tell me the best way to avoid the error, and
get the "2008-12-31T23:59:60" output that I want.

Thanks!
Andrew
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.