[Locale] updated StubIntlDateFormatter::format() behavior for PHP >= 5.3.4

This commit is contained in:
Eriksen Costa 2012-04-08 19:21:28 -03:00
parent da0eaa63cc
commit 31dde144ff
2 changed files with 20 additions and 2 deletions

View File

@ -174,13 +174,18 @@ class StubIntlDateFormatter
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'timestamp', $timestamp, 'Only integer unix timestamps are supported');
}
if (!is_int($timestamp)) {
// behave like the intl extension
// behave like the intl extension
if (!is_int($timestamp) && version_compare(\PHP_VERSION, '5.3.4', '<')) {
StubIntl::setErrorCode(StubIntl::U_ILLEGAL_ARGUMENT_ERROR);
return false;
}
// As of PHP 5.3.4, IntlDateFormatter::format() accepts DateTime instances
if ($timestamp instanceOf \DateTime && version_compare(\PHP_VERSION, '5.3.4', '>=')) {
$timestamp = $timestamp->getTimestamp();
}
$transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId());
$formatted = $transformer->format($this->createDateTime($timestamp));

View File

@ -276,6 +276,19 @@ class StubIntlDateFormatterTest extends LocaleTestCase
array('zzzzz', 0, 'GMT+00:00'),
);
// As of PHP 5.3.4, IntlDateFormatter::format() accepts DateTime instances
if (version_compare(\PHP_VERSION, '5.3.4', '>=')) {
$dateTime = new \DateTime('@0');
/* general, DateTime */
$formatData[] = array('y-M-d', $dateTime, '1970-1-1');
$formatData[] = array("yyyy.MM.dd 'at' HH:mm:ss zzz", $dateTime, '1970.01.01 at 00:00:00 GMT+00:00');
$formatData[] = array("EEE, MMM d, ''yy", $dateTime, "Thu, Jan 1, '70");
$formatData[] = array('h:mm a', $dateTime, '12:00 AM');
$formatData[] = array('K:mm a, z', $dateTime, '0:00 AM, GMT+00:00');
$formatData[] = array('yyyyy.MMMM.dd hh:mm aaa', $dateTime, '01970.January.01 12:00 AM');
}
return $formatData;
}