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]);
}

this lets us say things like:

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

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

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

Then there'd also be similar versions of gt, lt and cmp:
sub greater {
    $_[0]->clone->truncate(to=>$_[1]) > $_[2]->clone->truncate(to=>$_[0]);
}
sub lesser {
    $_[0]->clone->truncate(to=>$_[1]) < $_[2]->clone->truncate(to=>$_[0]);
}
sub compare { # Written quick, there could be a better way!
    return 1 if $_[0]->greater($_[1],$_[2]);
    return -1 if $_[0]->lesser($_[1],$_[2]);
    return 0;
}

Note: I use 'same' rather than 'equal' as the two objects aren't 'equal' but
they do share the 'same' day.

Cheers!
Rick

Reply via email to