Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6ded31a

Browse filesBrowse files
committed
[Intl] handle null date and time types
1 parent f82beb5 commit 6ded31a
Copy full SHA for 6ded31a

File tree

Expand file treeCollapse file tree

2 files changed

+35
-21
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+35
-21
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php
+21-21Lines changed: 21 additions & 21 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 \IntlTimeZone|\DateTimeZone|string|null $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|null $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
@@ -142,8 +142,8 @@ public function __construct($locale, $datetype, $timetype, $timezone = null, $ca
142142
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'calendar', $calendar, 'Only the GREGORIAN calendar is supported');
143143
}
144144

145-
$this->datetype = $datetype;
146-
$this->timetype = $timetype;
145+
$this->datetype = null !== $datetype ? $datetype : self::FULL;
146+
$this->timetype = null !== $timetype ? $timetype : self::FULL;
147147

148148
$this->setPattern($pattern);
149149
$this->setTimeZone($timezone);
@@ -152,13 +152,13 @@ public function __construct($locale, $datetype, $timetype, $timezone = null, $ca
152152
/**
153153
* Static constructor.
154154
*
155-
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en")
156-
* @param int $datetype Type of date formatting, one of the format type constants
157-
* @param int $timetype Type of time formatting, one of the format type constants
158-
* @param string $timezone Timezone identifier
159-
* @param int $calendar Calendar to use for formatting or parsing; default is Gregorian
160-
* One of the calendar constants
161-
* @param string $pattern Optional pattern to use when formatting
155+
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en")
156+
* @param int|null $datetype Type of date formatting, one of the format type constants
157+
* @param int|null $timetype Type of time formatting, one of the format type constants
158+
* @param \IntlTimeZone|\DateTimeZone|string|null $timezone Timezone identifier
159+
* @param int $calendar Calendar to use for formatting or parsing; default is Gregorian
160+
* One of the calendar constants
161+
* @param string|null $pattern Optional pattern to use when formatting
162162
*
163163
* @return self
164164
*
@@ -485,7 +485,7 @@ public function setLenient($lenient)
485485
/**
486486
* Set the formatter's pattern.
487487
*
488-
* @param string $pattern A pattern string in conformance with the ICU IntlDateFormatter documentation
488+
* @param string|null $pattern A pattern string in conformance with the ICU IntlDateFormatter documentation
489489
*
490490
* @return bool true on success or false on failure
491491
*
@@ -506,9 +506,9 @@ public function setPattern($pattern)
506506
/**
507507
* Set the formatter's timezone identifier.
508508
*
509-
* @param string $timeZoneId The time zone ID string of the time zone to use.
510-
* If NULL or the empty string, the default time zone for the
511-
* runtime is used.
509+
* @param string|null $timeZoneId The time zone ID string of the time zone to use.
510+
* If NULL or the empty string, the default time zone for the
511+
* runtime is used.
512512
*
513513
* @return bool true on success or false on failure
514514
*
@@ -552,7 +552,7 @@ public function setTimeZoneId($timeZoneId)
552552
/**
553553
* This method was added in PHP 5.5 as replacement for `setTimeZoneId()`.
554554
*
555-
* @param mixed $timeZone
555+
* @param \IntlTimeZone|\DateTimeZone|string|null $timeZone
556556
*
557557
* @return bool true on success or false on failure
558558
*

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php
+14Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.