Skip to content

Commit

Permalink
[Locale] Fix failing StubIntlDateFormatter in PHP 5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
stloyd committed Jan 4, 2013
1 parent 8ae773b commit 913b564
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php
Expand Up @@ -188,6 +188,9 @@ public function format($timestamp)
$argumentError = 'datefmt_format: takes either an array or an integer timestamp value ';
} elseif (version_compare(\PHP_VERSION, '5.3.4', '>=') && !is_int($timestamp) && !$timestamp instanceof \DateTime) {
$argumentError = 'datefmt_format: takes either an array or an integer timestamp value or a DateTime object';
if (version_compare(\PHP_VERSION, '5.5.0alpha1', '>=') && !is_int($timestamp)) {
$argumentError = sprintf('datefmt_format: string \'%s\' is not numeric, which would be required for it to be a valid date', $timestamp);
}
}

if (null !== $argumentError) {
Expand Down Expand Up @@ -313,9 +316,30 @@ public function getTimeZoneId()
return $this->timeZoneId;
}

// In PHP 5.5 default timezone depends on `date_default_timezone_get()` method
if (version_compare(\PHP_VERSION, '5.5.0alpha1', '>=')) {
return date_default_timezone_get();
}

return null;
}

/**
* Returns the formatter's timezone
*
* @return \DateTimeZone The timezone identifier used by the formatter
*
* @see http://www.php.net/manual/en/intldateformatter.gettimezone.php
*/
public function getTimeZone()
{
if (!$this->unitializedTimeZoneId) {
return new \DateTimeZone($this->timeZoneId);
}

return new \DateTimeZone(date_default_timezone_get());
}

/**
* Returns whether the formatter is lenient
*
Expand Down Expand Up @@ -490,13 +514,18 @@ public function setTimeZoneId($timeZoneId)
return true;
}

public function setTimeZone($timeZoneId)
{
return $this->setTimeZoneId($timeZoneId);
}

/**
* Create and returns a DateTime object with the specified timestamp and with the
* current time zone
*
* @param int $timestamp
*
* @return DateTime
* @return \DateTime
*/
protected function createDateTime($timestamp)
{
Expand Down

0 comments on commit 913b564

Please sign in to comment.