本文整理汇总了PHP中CDate::convertTZ方法的典型用法代码示例。如果您正苦于以下问题:PHP CDate::convertTZ方法的具体用法?PHP CDate::convertTZ怎么用?PHP CDate::convertTZ使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDate
的用法示例。
在下文中一共展示了CDate::convertTZ方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testConvertTZ
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);
}
示例2: compare
/**
* 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);
}