Skip to content

Commit

Permalink
[Intl] handle null date and time types
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Dec 31, 2018
1 parent f82beb5 commit 9f78a98
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php
Expand Up @@ -118,13 +118,13 @@ class IntlDateFormatter
private $timeZoneId;

/**
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en")
* @param int $datetype Type of date formatting, one of the format type constants
* @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 (or null using the default calendar, i.e. "GREGORIAN")
* @param string $pattern Optional pattern to use when formatting
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en")
* @param int|null $datetype Type of date formatting, one of the format type constants
* @param int|null $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 (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
* @see http://userguide.icu-project.org/formatparse/datetime
Expand All @@ -144,6 +144,8 @@ public function __construct($locale, $datetype, $timetype, $timezone = null, $ca

$this->datetype = $datetype;
$this->timetype = $timetype;
$this->datetype = null !== $datetype ? $datetype : self::FULL;
$this->timetype = null !== $timetype ? $timetype : self::FULL;

$this->setPattern($pattern);
$this->setTimeZone($timezone);
Expand Down
Expand Up @@ -46,6 +46,20 @@ public function testConstructorDefaultTimeZone()
);
}

public function testConstructorWithoutDateType()
{
$formatter = new IntlDateFormatter('en', null, IntlDateFormatter::SHORT, 'UTC', IntlDateFormatter::GREGORIAN);

$this->assertSame('EEEE, LLLL d, y, h:mm a', $formatter->getPattern());
}

public function testConstructorWithoutTimeType()
{
$formatter = new IntlDateFormatter('en', IntlDateFormatter::SHORT, null, 'UTC', IntlDateFormatter::GREGORIAN);

$this->assertSame('M/d/yy, h:mm:ss a zzzz', $formatter->getPattern());
}

/**
* @dataProvider formatProvider
*/
Expand Down

0 comments on commit 9f78a98

Please sign in to comment.