On Thursday, May 29, 2003, at 09:39 PM, Rick Measham wrote:


Looking through the FAQ (thanks Ben!), the question about comparisons is
raised. Clearly DT->now is only == to DT->today for one nanosecond.


Maybe we should add a routine such as the following to the core?

sub same {
$_[0]->clone->truncate(to=>$_[1]) == $_[2]->clone->truncate(to=>$_[0]);
}

I think you meant:


$_[0]->clone->truncate(to=>$_[1]) == $_[2]->clone->truncate(to=>$_[1])
^
this lets us say things like:

if (same($dt1,'day',$dt2)) { ... }

Eew.



Or, if you want to use it as an object method:


if ($dt1->same('day',$dt2)) { ... }

- What about testing more than two DT objects at a time?
- What is "same"? Basing it on truncate wouldn't allow testing for things like the same hour on different dates.
- I'm not opposed to something like a DT::Utilities module, as your next post mentions, but this could become a catch-all for a bunch of hacks that add cruft or that veer off the DT API when the powers of DT are sufficient.
- Isn't this pretty useful as is?
if ($dt1->day == $dt2->day) { ... }
if ($dt1->day_of_week == $dt2->day_of_week) { ... }


Maybe there are some other examples that show how same() would be usefully implemented?

Also, thanks, Ben!

- Bruce

__bruce__van_allen__santa_cruz__ca__

Reply via email to