Skip to content

Commit 9f78a98

Browse files
committed
[Intl] handle null date and time types
1 parent f82beb5 commit 9f78a98

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ class IntlDateFormatter
118118
private $timeZoneId;
119119

120120
/**
121-
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en")
122-
* @param int $datetype Type of date formatting, one of the format type constants
123-
* @param int $timetype Type of time formatting, one of the format type constants
124-
* @param mixed $timezone Timezone identifier
125-
* @param int $calendar Calendar to use for formatting or parsing. The only currently
126-
* supported value is IntlDateFormatter::GREGORIAN (or null using the default calendar, i.e. "GREGORIAN")
127-
* @param string $pattern Optional pattern to use when formatting
121+
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en")
122+
* @param int|null $datetype Type of date formatting, one of the format type constants
123+
* @param int|null $timetype Type of time formatting, one of the format type constants
124+
* @param mixed $timezone Timezone identifier
125+
* @param int $calendar Calendar to use for formatting or parsing. The only currently
126+
* supported value is IntlDateFormatter::GREGORIAN (or null using the default calendar, i.e. "GREGORIAN")
127+
* @param string $pattern Optional pattern to use when formatting
128128
*
129129
* @see http://www.php.net/manual/en/intldateformatter.create.php
130130
* @see http://userguide.icu-project.org/formatparse/datetime
@@ -144,6 +144,8 @@ public function __construct($locale, $datetype, $timetype, $timezone = null, $ca
144144

145145
$this->datetype = $datetype;
146146
$this->timetype = $timetype;
147+
$this->datetype = null !== $datetype ? $datetype : self::FULL;
148+
$this->timetype = null !== $timetype ? $timetype : self::FULL;
147149

148150
$this->setPattern($pattern);
149151
$this->setTimeZone($timezone);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ public function testConstructorDefaultTimeZone()
4646
);
4747
}
4848

49+
public function testConstructorWithoutDateType()
50+
{
51+
$formatter = new IntlDateFormatter('en', null, IntlDateFormatter::SHORT, 'UTC', IntlDateFormatter::GREGORIAN);
52+
53+
$this->assertSame('EEEE, LLLL d, y, h:mm a', $formatter->getPattern());
54+
}
55+
56+
public function testConstructorWithoutTimeType()
57+
{
58+
$formatter = new IntlDateFormatter('en', IntlDateFormatter::SHORT, null, 'UTC', IntlDateFormatter::GREGORIAN);
59+
60+
$this->assertSame('M/d/yy, h:mm:ss a zzzz', $formatter->getPattern());
61+
}
62+
4963
/**
5064
* @dataProvider formatProvider
5165
*/

0 commit comments

Comments
 (0)