(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL >= 3.0.0a1)
IntlCalendar::equals — 比較兩個 IntlCalendar 物件的時間是否相等
物件導向風格
程序式風格
如果此日曆與給定日曆的時間相同,則返回 true。設定、日曆類型和欄位狀態不必相同。
calendar
一個 IntlCalendar 實例。
other
要與主要物件比較的日曆。
如果此日曆和傳入的 IntlCalendar 物件的目前時間相同,則返回 true
,否則返回 false
。
失敗時也會返回 false
。要檢測錯誤狀況,請使用 intl_get_error_code(),或設定 Intl 拋出例外。
範例 #1 IntlCalendar::equals()
<?php
ini_set('date.timezone', 'UTC');
$cal1 = IntlCalendar::createInstance(NULL, 'es_ES');
$cal2 = clone $cal1;
var_dump($cal1->equals($cal2)); //TRUE
//The locale is not included in the comparison
$cal2 = IntlCalendar::createInstance(NULL, 'pt_PT');
$cal2->setTime($cal1->getTime());
var_dump($cal1->equals($cal2)); //TRUE
//And set fields state is not included as well
$cal2->clear(IntlCalendar::FIELD_YEAR);
var_dump($cal1->isSet(IntlCalendar::FIELD_YEAR) ==
$cal2->isSet(IntlCalendar::FIELD_YEAR)); //FALSE
var_dump($cal1->equals($cal2)); //TRUE
//Neither is the calendar type
$cal2 = IntlCalendar::createInstance(NULL, 'es_ES@calendar=islamic');
$cal2->setTime($cal1->getTime());
var_dump($cal1->equals($cal2)); //TRUE
//Only the time is
$cal2 = clone $cal1;
$cal2->setTime($cal1->getTime() + 1.);
var_dump($cal1->equals($cal2)); //FALSE