Skip to content

Commit ac604cb

Browse files
committed
bug #19751 Fixes the calendar in constructor to handle null (wakqasahmed)
This PR was merged into the 2.7 branch. Discussion ---------- Fixes the calendar in constructor to handle null | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19688 | License | MIT | Doc PR | none Fix the calendar exception to handle null, error was raised while exporting from akeneo The Symfony\Component\Intl\DateFormatter\IntlDateFormatter::__construct() method's argument $calendar value NULL behavior is not implemented. Only the GREGORIAN calendar is supported. Please install the "intl" extension for full localization capabilities. https://cloud.githubusercontent.com/assets/4486133/17287404/81f951cc-57e0-11e6-9f6f-e231bbf00bf4.png Commits ------- 43f2672 Fixes the calendar in constructor to handle null
2 parents af81c8c + 43f2672 commit ac604cb

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class IntlDateFormatter
134134
* @param int $timetype Type of time formatting, one of the format type constants
135135
* @param mixed $timezone Timezone identifier
136136
* @param int $calendar Calendar to use for formatting or parsing. The only currently
137-
* supported value is IntlDateFormatter::GREGORIAN.
137+
* supported value is IntlDateFormatter::GREGORIAN (or null using the default calendar, i.e. "GREGORIAN")
138138
* @param string $pattern Optional pattern to use when formatting
139139
*
140140
* @see http://www.php.net/manual/en/intldateformatter.create.php
@@ -149,7 +149,7 @@ public function __construct($locale, $datetype, $timetype, $timezone = null, $ca
149149
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
150150
}
151151

152-
if (self::GREGORIAN !== $calendar) {
152+
if (self::GREGORIAN !== $calendar && null !== $calendar) {
153153
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'calendar', $calendar, 'Only the GREGORIAN calendar is supported');
154154
}
155155

src/Symfony/Component/Intl/Tests/DateFormatter/IntlDateFormatterTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public function testConstructorWithoutLocale()
2828
$this->assertEquals('y-M-d', $formatter->getPattern());
2929
}
3030

31+
public function testConstructorWithoutCalendar()
32+
{
33+
$formatter = new IntlDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, 'UTC', null, 'y-M-d');
34+
$this->assertEquals('y-M-d', $formatter->getPattern());
35+
}
36+
3137
/**
3238
* @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
3339
*/

0 commit comments

Comments
 (0)