On Thu, 13 May 2004, Danny Rathjens wrote:
> Am I misunderstanding these methods or is this a bug? ;)
You're misunderstanding, but it may be a doc problem.
> perl -MData::Dumper -MDateTime -wle'$past = DateTime->now->subtract(months=>2); $now
> = DateTime->now; $dur = $now->delta_days($past); print Dumper $dur; print $dur->days'
> $VAR1 = bless( {
> 'seconds' => 0,
> 'minutes' => 0,
> 'end_of_month' => 'wrap',
> 'nanoseconds' => 0,
> 'days' => 61,
> 'months' => 0,
> 'sign' => 1
> }, 'DateTime::Duration' );
>
> 5
If you asked for $dur->weeks you'd get 8 weeks. 8 weeks + 5 days equals
61 days total.
If you asked for $dur->delta_days or $dur->in_units('days') you'd get 61.
> perl -MData::Dumper -MDateTime -wle'$past = DateTime->now->subtract(months=>2); $now
> = DateTime->now; $dur = $now - $past; print Dumper $dur; print $dur->delta_days'
> $VAR1 = bless( {
> 'seconds' => 0,
> 'minutes' => 0,
> 'end_of_month' => 'wrap',
> 'nanoseconds' => 0,
> 'days' => 0,
> 'months' => 2,
> 'sign' => 1
> }, 'DateTime::Duration' );
>
> 0
This I think is pretty straightforward. There is no way to convert months
to days or vice versa.
I've added something to the docs which will hopefully clarify this. In
general, I'd recommend people consider using DateTime::Format::Duration,
since it's much easier to get exactly what you want using that module.
-dave
/*=======================
House Absolute Consulting
www.houseabsolute.com
=======================*/