[EMAIL PROTECTED] schreef:
> I was wondering if DateTime has a method for converting rata die (in
> particular rd seconds) to a gregorian date?  I've done a bit of digging,
> but I'm not finding one, only methods for going G -> RD.
> 
> If not, does anyone have a handy wodge of Perl lying around to do this bit
> of magic?

rata die are the standard way to convert between different calendars, so
it's surprising that there is no convenient way to access them.

If your rd is expressed in days and seconds, this bit of code will
work:

    # (all code is untested! but except for typos, it should work)

    sub RD::utc_rd_values {
        return @{shift()};
    }

    my $temp = bless [$rd_days, $rd_secs], 'RD';

    my $dt = DateTime->from_object( object => $temp );

If your rd is expressed only in seconds, and leap seconds are not included,
you can use

    (my $rd_days, $rd_secs) = (int($rd_secs/86_400), $rd_secs%86_400);

to convert to days/secs. Or use one of our fabulous DT::Format modules
to do the RD->DateTime conversion:

    use DateTime::Format::Epoch;
    my $formatter = DateTime::Format::Epoch->new(
            epoch => DateTime->new( year => 1, month => 1, day => 1)
    );

    my $dt = $formatter->parse_datetime( $rd_secs );

Eugene

Reply via email to