From 43f26727d0e1c084cf125f06f604ddab1e820537 Mon Sep 17 00:00:00 2001 From: Waqas Ahmed Date: Fri, 26 Aug 2016 20:13:58 +0400 Subject: [PATCH] Fixes the calendar in constructor to handle null --- .../Component/Intl/DateFormatter/IntlDateFormatter.php | 4 ++-- .../Intl/Tests/DateFormatter/IntlDateFormatterTest.php | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php b/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php index 32d77784ac..c3b85bbb6f 100644 --- a/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php +++ b/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php @@ -134,7 +134,7 @@ class IntlDateFormatter * @param int $timetype Type of time formatting, one of the format type constants * @param mixed $timezone Timezone identifier * @param int $calendar Calendar to use for formatting or parsing. The only currently - * supported value is IntlDateFormatter::GREGORIAN. + * supported value is IntlDateFormatter::GREGORIAN (or null using the default calendar, i.e. "GREGORIAN") * @param string $pattern Optional pattern to use when formatting * * @see http://www.php.net/manual/en/intldateformatter.create.php @@ -149,7 +149,7 @@ class IntlDateFormatter throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported'); } - if (self::GREGORIAN !== $calendar) { + if (self::GREGORIAN !== $calendar && null !== $calendar) { throw new MethodArgumentValueNotImplementedException(__METHOD__, 'calendar', $calendar, 'Only the GREGORIAN calendar is supported'); } diff --git a/src/Symfony/Component/Intl/Tests/DateFormatter/IntlDateFormatterTest.php b/src/Symfony/Component/Intl/Tests/DateFormatter/IntlDateFormatterTest.php index b38d30cf6c..fde3bcde55 100644 --- a/src/Symfony/Component/Intl/Tests/DateFormatter/IntlDateFormatterTest.php +++ b/src/Symfony/Component/Intl/Tests/DateFormatter/IntlDateFormatterTest.php @@ -28,6 +28,12 @@ class IntlDateFormatterTest extends AbstractIntlDateFormatterTest $this->assertEquals('y-M-d', $formatter->getPattern()); } + public function testConstructorWithoutCalendar() + { + $formatter = new IntlDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, 'UTC', null, 'y-M-d'); + $this->assertEquals('y-M-d', $formatter->getPattern()); + } + /** * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException */