Home » Date and Time » Date » Bug #8267
changed behaviour of Date::compare, new method isSameDay
Details
| Request #8267 | changed behaviour of Date::compare, new method isSameDay |
|---|---|
| Submitted | 2006-07-23 11:07 UTC |
| From | ve dot ru at triosolutions dot at |
| Status | Suspended |
| Package | Date |
| PHP Version | Irrelevant |
| OS | Linux (irrelevant) |
| Roadmaps | (Not assigned) |
Comments
[2006-07-23 11:07 UTC] ve dot ru at triosolutions dot at
Description:
------------
Chaged the return values of Date::compare to different values to se if they are unequl in days, hours, minutes or seconds.
Changed Date::before and Date::after to follow the new return values.
Added a new method Date::isSameDay, which returns true if both Date instances are the same day, regardless of the time portion.
Test script:
---------------
In Date::compare, changed:
if ($days1 < $days2) return -1;
if ($days1 > $days2) return 1;
if ($d1->hour < $d2->hour) return -2;
if ($d1->hour > $d2->hour) return 2;
if ($d1->minute < $d2->minute) return -3;
if ($d1->minute > $d2->minute) return 3;
if ($d1->second < $d2->second) return -4;
if ($d1->second > $d2->second) return 4;
return 0;
New Method:
/**
* compares the current date to another Date instance. Returns true if
* both dates have same day. The time portion of both Date instances is ignored
* @param object Date $when: the object to compare
*/
function isSameDay($when) {
return abs(Date::compare($this, $when)) < 2 ? false : true;
}
Date::before, changed to: if (Date::compare($this,$when) < 0) {
Date::after, changed to: if (Date::compare($this,$when) > 0) {