10000 merged branch eriksencosta/locale (PR #3840) · phreaknerd/symfony@d865278 · GitHub
[go: up one dir, main page]

Skip to content

Commit d865278

Browse files
committed
merged branch eriksencosta/locale (PR symfony#3840)
Commits ------- 31dde14 [Locale] updated StubIntlDateFormatter::format() behavior for PHP >= 5.3.4 Discussion ---------- [Locale] updated StubIntlDateFormatter::format() behavior for PHP >= 5.3.4 Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: - Todo: - [![Build Status](https://secure.travis-ci.org/eriksencosta/symfony.png?branch=locale)](http://travis-ci.org/eriksencosta/symfony) --------------------------------------------------------------------------- by drak at 2012-04-08T23:20:20Z This looks like a feature addition as opposed to a bug fix and if so, should probably go in the master branch rather than 2.0. --------------------------------------------------------------------------- by stof at 2012-04-08T23:30:25Z @Drak it is a bug fix as the stub is meant to have the same behavior than the real intl --------------------------------------------------------------------------- by drak at 2012-04-08T23:36:08Z ok, thanks for the clarification, I wasnt sure. --------------------------------------------------------------------------- by eriksencosta at 2012-04-08T23:44:22Z @stof is right. I myself fixed it in master and then remembered that bug fixes should be made in 2.0.
2 parents da0eaa6 + 31dde14 commit d865278

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,18 @@ public function format($timestamp)
174174
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'timestamp', $timestamp, 'Only integer unix timestamps are supported');
175175
}
176176

177-
if (!is_int($timestamp)) {
178-
// behave like the intl extension
177+
// behave like the intl extension
178+
if (!is_int($timestamp) && version_compare(\PHP_VERSION, '5.3.4', '<')) {
179179
StubIntl::setErrorCode(StubIntl::U_ILLEGAL_ARGUMENT_ERROR);
180180

181181
return false;
182182
}
183183

184+
// As of PHP 5.3.4, IntlDateFormatter::format() accepts DateTime instances
185+
if ($timestamp instanceOf \DateTime && version_compare(\PHP_VERSION, '5.3.4', '>=')) {
186+
$timestamp = $timestamp->getTimestamp();
187+
}
188+
184189
$transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId());
185190
$formatted = $transformer->format($this->createDateTime($timestamp));
186191

tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,19 @@ public function formatProvider()
276276
array('zzzzz', 0, 'GMT+00:00'),
277277
);
278278

279+
// As of PHP 5.3.4, IntlDateFormatter::format() accepts DateTime instances
280+
if (version_compare(\PHP_VERSION, '5.3.4', '>=')) {
281+
$dateTime = new \DateTime('@0');
282+
283+
/* general, DateTime */
284+
$formatData[] = array('y-M-d', $dateTime, '1970-1-1');
285+
$formatData[] = array("yyyy.MM.dd 'at' HH:mm:ss zzz", $dateTime, '1970.01.01 at 00:00:00 GMT+00:00');
286+
$formatData[] = array("EEE, MMM d, ''yy", $dateTime, "Thu, Jan 1, '70");
287+
$formatData[] = array('h:mm a', $dateTime, '12:00 AM');
288+
$formatData[] = array('K:mm a, z', $dateTime, '0:00 AM, GMT+00:00');
289+
$formatData[] = array('yyyyy.MMMM.dd hh:mm aaa', $dateTime, '01970.January.01 12:00 AM');
290+
}
291+
279292
return $formatData;
280293
}
281294

0 commit comments

Comments
 (0)
0