On Tue, 16 Dec 2008, Perrin Harkins wrote:
On Mon, Dec 15, 2008 at 8:29 PM, Alex Teslik <[email protected]> wrote:
On Mon, 15 Dec 2008 20:04:26 -0500, Perrin Harkins wrote
my $d1 = DateTime->today;
my $d2 = $d1->clone->subtract(years => 1);
my $dur = $d1->delta_days($d2);
print $dur->in_units('days') . "\n";
corrected above. I don't know why the days method didn't work.
Thanks Alex. That does what I want.
Previously I was trying to make this work with overloaded subtraction
instead of delta_days():
my $dur = $d1 - $d2;
The object returned here gives '0' for days() and in_units('days') and
'1' for years(). I think that's by design, but something seems off
here, and my guess is that it's the return of days() on the
delta_days() Duration object (which gives me '2').
The whole subtraction API and DT::Duration API kind of suck. They accreted
over time and ended up rather confusing (thus two different delta_days
methods, one in DateTime.pm and the other in DT::Duration).
Unfortunately, at this point I feel the burden of backcompat, and I can't
see how to fix it without adding even more methods, which would have even
worse names.
But I'll fix it all when I do DateTime6, I promise ;)
-dave
/*============================================================
http://VegGuide.org http://blog.urth.org
Your guide to all that's veg House Absolute(ly Pointless)
============================================================*/