Re: rata die to gregorian?

2005-03-26 Thread Eugene van der Pijll
[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


rata die to gregorian?

2005-03-24 Thread kellan
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?

thanks
-kellan


-- 
we reject kings, presidents and voting. we believe in
rough consensus and running code. [david clark (MIT)]



Re: rata die to gregorian?

2005-03-24 Thread Dave Rolsky
On Thu, 24 Mar 2005 [EMAIL PROTECTED] wrote:
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.
Do you mean rata die days expressed in seconds (X * 86400)?
You could look in DateTimePP.pm and _rd2ymd and _seconds_as_components for 
similar code.  The latter assumes that it will never get more than (86400 
+ leap seconds) seconds.  You could first convert seconds to rata die 
days, and then convert each part separately.

The trick for what you're asking would be handling leap seconds.  Of 
course, if you don't need to it's trivial.

-dave
/*===
VegGuide.Orgwww.BookIRead.com
Your guide to all that's veg.   My book blog
===*/