From 73d9cef188511a2dee17a99630f2fc62cb3eded8 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Fri, 4 Jan 2013 15:29:23 +0100 Subject: [PATCH] [Locale] Adjust `StubIntlDateFormatter` to have new methods added in PHP 5.5 --- .../Locale/Stub/StubIntlDateFormatter.php | 70 +++++++++++++++---- 1 file changed, 57 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php b/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php index 38fe8ae98a27..d64044710f01 100644 --- a/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php +++ b/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php @@ -217,6 +217,24 @@ public function format($timestamp) 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 * @@ -229,6 +247,20 @@ public function getCalendar() 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 * @@ -327,17 +359,15 @@ public function getTimeZoneId() /** * 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 + * + * @throws MethodNotImplementedException */ public function getTimeZone() { - if (!$this->unitializedTimeZoneId) { - return new \DateTimeZone($this->timeZoneId); - } - - return new \DateTimeZone(date_default_timezone_get()); + throw new MethodNotImplementedException(__METHOD__); } /** @@ -482,11 +512,16 @@ public function setPattern($pattern) public function setTimeZoneId($timeZoneId) { if (null === $timeZoneId) { - // 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. - // See the first two items of the commit message for more information: - // https://github.com/php/php-src/commit/eb346ef0f419b90739aadfb6cc7b7436c5b521d9 - $timeZoneId = getenv('TZ') ?: 'UTC'; + // 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 + // 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: + // https://github.com/php/php-src/commit/eb346ef0f419b90739aadfb6cc7b7436c5b521d9 + $timeZoneId = getenv('TZ') ?: 'UTC'; + } $this->unitializedTimeZoneId = true; } @@ -514,9 +549,18 @@ public function setTimeZoneId($timeZoneId) 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); } /**