Fixes the calendar in constructor to handle null

This commit is contained in:
Waqas Ahmed 2016-08-26 20:13:58 +04:00
parent af81c8cfad
commit 43f26727d0
2 changed files with 8 additions and 2 deletions

View File

@ -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');
}

View File

@ -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
*/