Skip to content

Commit

Permalink
bug #29738 [Intl] handle null date and time types (xabbuh)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.4 branch.

Discussion
----------

[Intl] handle null date and time types

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29705
| License       | MIT
| Doc PR        |

Commits
-------

6ded31a [Intl] handle null date and time types
  • Loading branch information
nicolas-grekas committed Jan 3, 2019
2 parents 05efd12 + 6ded31a commit c573cfb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
42 changes: 21 additions & 21 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 \IntlTimeZone|\DateTimeZone|string|null $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|null $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 @@ -142,8 +142,8 @@ public function __construct($locale, $datetype, $timetype, $timezone = null, $ca
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'calendar', $calendar, 'Only the GREGORIAN calendar is supported');
}

$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 All @@ -152,13 +152,13 @@ public function __construct($locale, $datetype, $timetype, $timezone = null, $ca
/**
* Static constructor.
*
* @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 string $timezone Timezone identifier
* @param int $calendar Calendar to use for formatting or parsing; default is Gregorian
* One of the calendar constants
* @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 \IntlTimeZone|\DateTimeZone|string|null $timezone Timezone identifier
* @param int $calendar Calendar to use for formatting or parsing; default is Gregorian
* One of the calendar constants
* @param string|null $pattern Optional pattern to use when formatting
*
* @return self
*
Expand Down Expand Up @@ -485,7 +485,7 @@ public function setLenient($lenient)
/**
* Set the formatter's pattern.
*
* @param string $pattern A pattern string in conformance with the ICU IntlDateFormatter documentation
* @param string|null $pattern A pattern string in conformance with the ICU IntlDateFormatter documentation
*
* @return bool true on success or false on failure
*
Expand All @@ -506,9 +506,9 @@ public function setPattern($pattern)
/**
* Set the formatter's timezone identifier.
*
* @param string $timeZoneId The time zone ID string of the time zone to use.
* If NULL or the empty string, the default time zone for the
* runtime is used.
* @param string|null $timeZoneId The time zone ID string of the time zone to use.
* If NULL or the empty string, the default time zone for the
* runtime is used.
*
* @return bool true on success or false on failure
*
Expand Down Expand Up @@ -552,7 +552,7 @@ public function setTimeZoneId($timeZoneId)
/**
* This method was added in PHP 5.5 as replacement for `setTimeZoneId()`.
*
* @param mixed $timeZone
* @param \IntlTimeZone|\DateTimeZone|string|null $timeZone
*
* @return bool true on success or false on failure
*
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 c573cfb

Please sign in to comment.