Dave,

  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?

  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).

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?

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.

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.

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.

Tim

On Mon, 13 Dec 2004, Dave Rolsky wrote:

> On Mon, 13 Dec 2004, Joshua Hoblitt wrote:
> 
> > It looks like the normalization is hosed.
> 
> This method, for the nth time, does not convert between units which do not 
> have a fixed conversion rate.
> 
> I'd also point out that it probably won't work well with non-integer 
> units.  I'm not sure what'll happen when you try to add 160.2 minutes to a 
> DateTime object, but it won't be anything good, I'm sure.
> 
> > use DateTime::Duration;
> >
> > my $dur = DateTime::Duration->new( hours => 2.67 );
> >
> > print "hours: ",        $dur->in_units( 'hours' ), "\n";
> 
> Prints 2, as you'd expect
> 
> > print "minutes: ",      $dur->in_units( 'minutes' ), "\n";
> 
> prints 160.2, which is right
> 
> > print "seconds: ",      $dur->in_units( 'seconds' ), "\n";
> 
> prints 0
> 
> > print "nanoseconds: ",  $dur->in_units( 'nanoseconds' ), "\n";
> 
> also 0
> 
> >> How can that be sane? So you ask for minutes and you get fractional
> >> minutes but you ask for seconds and get zero?
> 
> Cause really it should just blow up when you give it fractional anything.
> 
> 
> -dave
> 
> /*===========================
> VegGuide.Org
> Your guide to all that's veg.
> ===========================*/
> 

-- 
Tim Jenness
JAC software
http://www.jach.hawaii.edu/~timj

Reply via email to