Dave Rolsky wrote:
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.

ok, I was confused into thinking this was possible by my $dur = $now->delta_days($past)
in my first example, which results in 61 days due to a two month difference.
I realize now that DT::delta_days means something different than 
DT::Duration::delta_days
since DT::delta_days knows whether it is a leap year but a DT::Duration object doesn't.
Perhaps if you could anchor one end of the duration you would be able to convert all of
the components of a duration into a single unit; ah I guess that is what DT::Span is 
for.
Or just using epochs, :)

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.

Thanks very much for your hard work on these great modules.
--
    _.,-*~`^'~*-,._ Danny Rathjens _.,-*~`^'~*-,._
FireCast: Rock solid kiosk software: http://wirespring.com

Reply via email to