Skip to content

Commit

Permalink
[Intl] Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jan 11, 2023
1 parent d7132b1 commit f378eb6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
10 changes: 9 additions & 1 deletion DateFormatter/DateFormat/QuarterTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@ public function format(\DateTime $dateTime, int $length): string
return $this->padLeft($quarter, $length);
case 3:
return 'Q'.$quarter;
default:
case 4:
$map = [1 => '1st quarter', 2 => '2nd quarter', 3 => '3rd quarter', 4 => '4th quarter'];

return $map[$quarter];
default:
if (\defined('INTL_ICU_VERSION') && version_compare(\INTL_ICU_VERSION, '70.1', '<')) {
$map = [1 => '1st quarter', 2 => '2nd quarter', 3 => '3rd quarter', 4 => '4th quarter'];

return $map[$quarter];
} else {
return $quarter;
}
}
}

Expand Down
30 changes: 28 additions & 2 deletions Tests/DateFormatter/AbstractIntlDateFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ public function formatProvider()
$dateTime = new \DateTime('@0');
$dateTimeImmutable = new \DateTimeImmutable('@0');

/* https://unicode-org.atlassian.net/browse/ICU-21647 */
$expectedQuarterX5 = '1';
if (\defined('INTL_ICU_VERSION') && version_compare(\INTL_ICU_VERSION, '70.1', '<')) {
$expectedQuarterX5 = '1st quarter';
}

$formatData = [
/* general */
['y-M-d', 0, '1970-1-1'],
Expand Down Expand Up @@ -144,13 +150,13 @@ public function formatProvider()
['QQ', 0, '01'],
['QQQ', 0, 'Q1'],
['QQQQ', 0, '1st quarter'],
['QQQQQ', 0, '1st quarter'],
['QQQQQ', 0, $expectedQuarterX5],

['q', 0, '1'],
['qq', 0, '01'],
['qqq', 0, 'Q1'],
['qqqq', 0, '1st quarter'],
['qqqqq', 0, '1st quarter'],
['qqqqq', 0, $expectedQuarterX5],

// 4 months
['Q', 7776000, '2'],
Expand Down Expand Up @@ -363,6 +369,10 @@ public function formatWithTimezoneProvider()
*/
public function testFormatTimezone($pattern, $timezone, $expected)
{
if ((80114 === \PHP_VERSION_ID || 80201 === \PHP_VERSION_ID) && str_contains($timezone, 'GMT')) {
$this->markTestSkipped('Broken version of PHP');
}

$formatter = $this->getDefaultDateFormatter($pattern);
$formatter->setTimeZone(new \DateTimeZone($timezone));

Expand Down Expand Up @@ -421,6 +431,10 @@ public function formatTimezoneProvider()

public function testFormatWithGmtTimezone()
{
if (80114 === \PHP_VERSION_ID || 80201 === \PHP_VERSION_ID) {
$this->markTestSkipped('Broken version of PHP');
}

$formatter = $this->getDefaultDateFormatter('zzzz');

$formatter->setTimeZone('GMT+03:00');
Expand All @@ -430,6 +444,10 @@ public function testFormatWithGmtTimezone()

public function testFormatWithGmtTimeZoneAndMinutesOffset()
{
if (80114 === \PHP_VERSION_ID || 80201 === \PHP_VERSION_ID) {
$this->markTestSkipped('Broken version of PHP');
}

$formatter = $this->getDefaultDateFormatter('zzzz');

$formatter->setTimeZone('GMT+00:30');
Expand Down Expand Up @@ -794,6 +812,10 @@ public function parseSecondProvider()

public function parseTimezoneProvider()
{
if (80114 === \PHP_VERSION_ID || 80201 === \PHP_VERSION_ID) {
return [['y-M-d HH:mm:ss', '1970-1-1 00:00:00', 0]];
}

return [
['y-M-d HH:mm:ss zzzz', '1970-1-1 00:00:00 GMT-03:00', 10800],
['y-M-d HH:mm:ss zzzz', '1970-1-1 00:00:00 GMT-04:00', 14400],
Expand Down Expand Up @@ -912,6 +934,10 @@ public function testSetPattern()
*/
public function testSetTimeZoneId($timeZoneId, $expectedTimeZoneId)
{
if ((80114 === \PHP_VERSION_ID || 80201 === \PHP_VERSION_ID) && str_contains($timeZoneId ?? '', 'GMT')) {
$this->markTestSkipped('Broken version of PHP');
}

$formatter = $this->getDefaultDateFormatter();

$formatter->setTimeZone($timeZoneId);
Expand Down
4 changes: 4 additions & 0 deletions Tests/DateFormatter/IntlDateFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ public function testParseThreeDigitsYears()

protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter::GREGORIAN, $pattern = null)
{
if ((80114 === \PHP_VERSION_ID || 80201 === \PHP_VERSION_ID) && \is_string($timezone) && str_contains($timezone, 'GMT')) {
$this->markTestSkipped('Broken version of PHP');
}

return new class($locale, $datetype, $timetype, $timezone, $calendar, $pattern) extends IntlDateFormatter {
};
}
Expand Down
8 changes: 8 additions & 0 deletions Tests/DateFormatter/Verification/IntlDateFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ protected function setUp(): void
*/
public function testFormatTimezone($pattern, $timezone, $expected)
{
if ((80114 === \PHP_VERSION_ID || 80201 === \PHP_VERSION_ID) && str_contains($timezone, 'GMT')) {
$this->markTestSkipped('Broken version of PHP');
}

IntlTestHelper::requireFullIntl($this, '59.1');

parent::testFormatTimezone($pattern, $timezone, $expected);
Expand All @@ -59,6 +63,10 @@ public function testDateAndTimeType($timestamp, $datetype, $timetype, $expected)

protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter::GREGORIAN, $pattern = null)
{
if ((80114 === \PHP_VERSION_ID || 80201 === \PHP_VERSION_ID) && \is_string($timezone) && str_contains($timezone, 'GMT')) {
$this->markTestSkipped('Broken version of PHP');
}

IntlTestHelper::requireFullIntl($this, '55.1');

if (!$formatter = new \IntlDateFormatter($locale, $datetype ?? IntlDateFormatter::FULL, $timetype ?? IntlDateFormatter::FULL, $timezone, $calendar, $pattern)) {
Expand Down

0 comments on commit f378eb6

Please sign in to comment.