CakeFest 2024: The Official CakePHP Conference

IntlCalendar::isLenient

(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL >= 3.0.0a1)

IntlCalendar::isLenient日付と時刻の解釈を「緩いモード」で行うかを取得する

説明

オブジェクト指向型

public IntlCalendar::isLenient(): bool

手続き型

intlcal_is_lenient(IntlCalendar $calendar): bool

現在の日付/時刻の解釈が「緩いモード」(デフォルト) で行われているかを返します。 緩いモードの場合、フィールドの範囲外の値によっては、 エラーを発生させることなく受け入れられる場合があります。

パラメータ

calendar

IntlCalendar クラスのインスタンス。

戻り値

カレンダーが「緩いモード」に設定されているかどうかを bool で返します。

例1 IntlCalendar::isLenient()

<?php
ini_set
('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'pt_PT');
ini_set('intl.use_exceptions', '1');

$cal = new IntlGregorianCalendar(2013, 6 /* July */, 1);
var_dump(IntlDateFormatter::formatObject($cal), // 01/07/2013, 00:00:00
$cal->isLenient()); // true

$cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 33);
var_dump(IntlDateFormatter::formatObject($cal)); // 02/08/2013, 00:00:00

$cal->setLenient(false);
var_dump($cal->isLenient()); // false
$cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 33);
var_dump(IntlDateFormatter::formatObject($cal)); // error

上の例の出力は以下となります。

string(20) "01/07/2013, 00:00:00"
bool(true)
string(20) "02/08/2013, 00:00:00"
bool(false)

Fatal error: Uncaught exception 'IntlException' with message 'datefmt_format_object: error obtaining instant from IntlCalendar' in /home/foobar/example.php:16
Stack trace:
#0 /home/foobar/example.php(16): IntlDateFormatter::formatObject(Object(IntlGregorianCalendar))
#1 {main}
  thrown in /home/foobar/example.php on line 16

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top