On Fri, 14 May 2004, Danny Rathjens wrote:Ah, I see what you mean. I missed the 'base' option when I first skimmed it.
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.
Actually, you can do that with DT::F::Duration.
# This returned '60' until I added the 'base'.
[EMAIL PROTECTED]:~/tst% perl -MDateTime::Format::Duration -MDateTime -wle'$past = DateTime->now->subtract(months=>2); $now = DateTime->now; $dur = $now - $past; my $dfd = DateTime::Format::Duration->new(pattern=>"%j",base => $now);print $dfd->format_duration($dur);'
61
That seems a bit overcomplicated just to figure out the number of days between two dates, though.
Is there anything wrong with using this?: [EMAIL PROTECTED]:~/tst% perl -MDateTime -wle'$past = DateTime->now->subtract(months=>2); print DateTime->now->delta_days($past)->delta_days' 61
I did manage to get some inconsistencies by making the duration bigger, :) perl -MDateTime::Format::Duration -MDateTime -wle'$past = DateTime->now->subtract(years=>7,months=>2,days=>17); $now = DateTime->now; $dur = $now - $past; my $dfd = DateTime::Format::Duration->new(pattern=>"%j",base => $now);print $dfd->format_duration($dur);' 2632 [EMAIL PROTECTED]:~/tst% perl -MData::Dumper -MDateTime -wle'$past = DateTime->now->subtract(years=>7,months=>2,days=>17); print DateTime->now->delta_days($past)->delta_days' 2633 # this one uses $past instead of $now as 'base' [EMAIL PROTECTED]:~/tst% perl -MDateTime::Format::Duration -MDateTime -wle'$past = DateTime->now->subtract(years=>7,months=>2,days=>17); $now = DateTime->now; $dur = $now - $past; my $dfd = DateTime::Format::Duration->new(pattern=>"%j",base => $past);print $dfd->format_duration($dur);' 2629