On Mon, 13 Dec 2004, Tim Jenness wrote:

 Thanks for the reply. So are you saying that DateTime::Duration
shouldn't really be used at all if I have units of fractional anything and
want to convert that to a duration? I'm supposed to convert it first to
hours, minutes and seconds and then instantiate a DateTime::Duration from
that? Shouldn't there be DateTime warnings if that is attempted?

Yes, yes, and yes, it should, but it doesn't.

 What I don't understand is why converting a duration from fractional
hours, minutes and seconds is not a standard part of the module. It would
seem to be an obvious use for it (and I have lots of data sources that use
fractional hours or fractional seconds).

The problem (as I've reiterated many times) is that the number of seconds per minute is not fixed, nor are the number of hours per day.


DateTime::Format::Duration does handle fractional hours, minutes and
seconds but I can't see an obvious way to convert a
DateTime::Format::Duration object to a DateTime::Duration object
without saying something convoluted like:

 my $dur = DateTime::Duration->new(
         seconds => DateTime::Format::Duration->new(
         pattern => '%s')->format_duration_from_deltas( hours => 2.67 ))

which can't be the best way of doing this but does result in a Duration
object of 9612.2 sec but now I get:

 hours: 0
 minutes: 0
 seconds: 9612
 nanoseconds: 9612000000000

which also seems bizarre and non-obvious since I would expect
in_units('hours') to return '2'. How come seconds from the constructor
aren't converted to hours and minutes?

See above.

I'm not sure what "fixed conversion rate" means in this context but it
clearly doesn't mean divide seconds by 3600 to get hours.

Yeah, I need to make that clearer. The problem is that with leap seconds, there are a few 3601 second hours out there.


As a related aside. What is wrong with addiing 160.2 minutes to a DateTime
object? It seems to be a perfectly sensible thing to do if it is first
converted to seconds.

If you convert the .2 minutes to seconds first, yes, it is perfectly sensible.


Sorry to show my ignorance here but I am extremely confused by the fact
that I can't come up with any sane usage for a Duration object (I realise
that I'm probably being colored by assuming I can switch all my code from
Time::Seconds (part of Time::Piece) to DateTime::Duration with minimal
pain.

DT && DT::Duration are definitely not meant to emulate Time::Piece and Time::Seconds. Time::Seconds is intentionally bogus. For example, it assumes that each year has exactly 365.24225 days!


If you have data that assumes a 3600 second hour (for example TAI based data), then you'd have to convert fractional minutes into minutes + seconds before creating a new DT::Duration object. This could be wrapped up in a module easily.

Maybe it could be something like DT::Duration::Fractional? What do others think?


-dave

/*===========================
VegGuide.Org
Your guide to all that's veg.
===========================*/

Reply via email to