[Locale] Adjust StubIntlDateFormatter
to have new methods added in PHP 5.5
This commit is contained in:
parent
b2ce983596
commit
73d9cef188
@ -217,6 +217,24 @@ class StubIntlDateFormatter
|
|||||||
return $formatted;
|
return $formatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats an object
|
||||||
|
*
|
||||||
|
* @param object $object
|
||||||
|
* @param mixed $format
|
||||||
|
* @param string $locale
|
||||||
|
*
|
||||||
|
* @return string The formatted value
|
||||||
|
*
|
||||||
|
* @see http://www.php.net/manual/en/intldateformatter.formatobject.php
|
||||||
|
*
|
||||||
|
* @throws MethodNotImplementedException
|
||||||
|
*/
|
||||||
|
public function formatObject($object, $format = null, $locale = null)
|
||||||
|
{
|
||||||
|
throw new MethodNotImplementedException(__METHOD__);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the formatter's calendar
|
* Returns the formatter's calendar
|
||||||
*
|
*
|
||||||
@ -229,6 +247,20 @@ class StubIntlDateFormatter
|
|||||||
return self::GREGORIAN;
|
return self::GREGORIAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the formatter's calendar object
|
||||||
|
*
|
||||||
|
* @return object The calendar's object being used by the formatter
|
||||||
|
*
|
||||||
|
* @see http://www.php.net/manual/en/intldateformatter.getcalendarobject.php
|
||||||
|
*
|
||||||
|
* @throws MethodNotImplementedException
|
||||||
|
*/
|
||||||
|
public function getCalendarObject()
|
||||||
|
{
|
||||||
|
throw new MethodNotImplementedException(__METHOD__);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the formatter's datetype
|
* Returns the formatter's datetype
|
||||||
*
|
*
|
||||||
@ -327,17 +359,15 @@ class StubIntlDateFormatter
|
|||||||
/**
|
/**
|
||||||
* Returns the formatter's timezone
|
* Returns the formatter's timezone
|
||||||
*
|
*
|
||||||
* @return \DateTimeZone The timezone identifier used by the formatter
|
* @return mixed The timezone used by the formatter
|
||||||
*
|
*
|
||||||
* @see http://www.php.net/manual/en/intldateformatter.gettimezone.php
|
* @see http://www.php.net/manual/en/intldateformatter.gettimezone.php
|
||||||
|
*
|
||||||
|
* @throws MethodNotImplementedException
|
||||||
*/
|
*/
|
||||||
public function getTimeZone()
|
public function getTimeZone()
|
||||||
{
|
{
|
||||||
if (!$this->unitializedTimeZoneId) {
|
throw new MethodNotImplementedException(__METHOD__);
|
||||||
return new \DateTimeZone($this->timeZoneId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new \DateTimeZone(date_default_timezone_get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -482,11 +512,16 @@ class StubIntlDateFormatter
|
|||||||
public function setTimeZoneId($timeZoneId)
|
public function setTimeZoneId($timeZoneId)
|
||||||
{
|
{
|
||||||
if (null === $timeZoneId) {
|
if (null === $timeZoneId) {
|
||||||
|
// In PHP 5.5 if $timeZoneId is null it fallbacks to `date_default_timezone_get()` method
|
||||||
|
if (version_compare(\PHP_VERSION, '5.5.0alpha1', '>=')) {
|
||||||
|
$timeZoneId = date_default_timezone_get();
|
||||||
|
} else {
|
||||||
// TODO: changes were made to ext/intl in PHP 5.4.4 release that need to be investigated since it will
|
// TODO: changes were made to ext/intl in PHP 5.4.4 release that need to be investigated since it will
|
||||||
// use ini's date.timezone when the time zone is not provided. As a not well tested workaround, uses UTC.
|
// use ini's date.timezone when the time zone is not provided. As a not well tested workaround, uses UTC.
|
||||||
// See the first two items of the commit message for more information:
|
// See the first two items of the commit message for more information:
|
||||||
// https://github.com/php/php-src/commit/eb346ef0f419b90739aadfb6cc7b7436c5b521d9
|
// https://github.com/php/php-src/commit/eb346ef0f419b90739aadfb6cc7b7436c5b521d9
|
||||||
$timeZoneId = getenv('TZ') ?: 'UTC';
|
$timeZoneId = getenv('TZ') ?: 'UTC';
|
||||||
|
}
|
||||||
|
|
||||||
$this->unitializedTimeZoneId = true;
|
$this->unitializedTimeZoneId = true;
|
||||||
}
|
}
|
||||||
@ -514,9 +549,18 @@ class StubIntlDateFormatter
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTimeZone($timeZoneId)
|
/**
|
||||||
|
* This method was added in PHP 5.5 as replacement for `setTimeZoneId()`
|
||||||
|
*
|
||||||
|
* @param mixed $timeZone
|
||||||
|
*
|
||||||
|
* @return Boolean true on success or false on failure
|
||||||
|
*
|
||||||
|
* @see http://www.php.net/manual/en/intldateformatter.settimezone.php
|
||||||
|
*/
|
||||||
|
public function setTimeZone($timeZone)
|
||||||
{
|
{
|
||||||
return $this->setTimeZoneId($timeZoneId);
|
return $this->setTimeZoneId($timeZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user