public function testConvertTZ() { $myDate1 = new CDate('', 'US/Eastern'); $this->assertEquals($myDate1, new CDate('', 'US/Eastern')); $myDate2 = new CDate('', 'CST'); $myDate2->convertTZ('EST'); //This tweaks the test data in case the +1 is across the day change. $tmpHour = $myDate1->hour + 1 >= 24 ? $myDate1->hour + 1 - 24 : $myDate1->hour + 1; $this->assertEquals($tmpHour, $myDate2->hour); $this->assertEquals($myDate1->minute, $myDate2->minute); $myDate2->convertTZ('PST'); $tmpHour = $myDate1->hour - 2 < 0 ? $myDate1->hour - 2 + 24 : $myDate1->hour - 2; $this->assertEquals($tmpHour, $myDate2->hour); }
/** * Overloaded compare method * * The convertTZ calls are time intensive calls. When a compare call is * made in a recussive loop the lag can be significant. */ function compare($d1, $d2, $convertTZ = false) { if (!is_object($d1)) { $d1 = new CDate($d1); } else { if (!is_object($d2)) { $d2 = new CDate($d2); } } if ($convertTZ) { $d1->convertTZ(new Date_TimeZone('UTC')); $d2->convertTZ(new Date_TimeZone('UTC')); } $days1 = Date_Calc::dateToDays($d1->day, $d1->month, $d1->year); $days2 = Date_Calc::dateToDays($d2->day, $d2->month, $d2->year); $comp_value = 0; if ($days1 - $days2) { $comp_value = $days1 - $days2; } else { if ($d1->hour - $d2->hour) { $comp_value = dPsgn($d1->hour - $d2->hour); } else { if ($d1->minute - $d2->minute) { $comp_value = dPsgn($d1->minute - $d2->minute); } else { if ($d1->second - $d2->second) { $comp_value = dPsgn($d1->second - $d2->second); } } } } return dPsgn($comp_value); }