Skip to content

Commit

Permalink
[Locale] Adjust StubIntlDateFormatter to have new methods added in …
Browse files Browse the repository at this point in the history
…PHP 5.5
  • Loading branch information
stloyd committed Jan 4, 2013
1 parent b2ce983 commit 73d9cef
Showing 1 changed file with 57 additions and 13 deletions.
70 changes: 57 additions & 13 deletions src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php
Expand Up @@ -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
*
Expand All @@ -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
*
Expand Down Expand Up @@ -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__);
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 73d9cef

Please sign in to comment.