On Thu, 30 Dec 2004, Max Campos wrote:

After feedback from another poster, it looks like the answer is the following:

$now->delta_days($dt)->in_units('days');

It looks like durations end up broken up into 4 partitions. Conversions can happen only within the partitions, not between:

years/months
weeks/days
hours/minutes
seconds/ns

Yes, _I_ know all this ;) I wrote it.

Also, maybe DateTime should throw some kind of error when you run in_units and a higher partition is being stripped off?

Ex:
my $dur = DateTime::Duration->new(months => 3, days=> 4);
$dur->in_units(days);  # Error; currently 4
$dur->in_units(years); # No error, 0.

It's not an error, and warnings for this sort of stuff will just annoy people.


Finally, I think some explanation should be added to DT:Duration::in_units that explains all of this!

I'll add it. The conversion issues are explained in DateTime.pm at length and mentioned in the DESCRIPTION section of DT::Duration, but not in the in_units method.



-dave

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

Reply via email to