Add test for ECMA402 PR 788 (#3917)

* Add test for ECMA402 PR 788

https://github.com/tc39/ecma402/pull/788

* Fix misunderstanding about "+00:00"

* Fix lint

* Swap actual, expected position

* Update test/intl402/DateTimeFormat/prototype/resolvedOptions/offset-timezone-change.js

Co-authored-by: Richard Gibson <richard.gibson@gmail.com>

* Update test/intl402/DateTimeFormat/prototype/resolvedOptions/offset-timezone-basic.js

Co-authored-by: Richard Gibson <richard.gibson@gmail.com>

* Update test/intl402/DateTimeFormat/prototype/formatToParts/offset-timezone-correct.js

Co-authored-by: Richard Gibson <richard.gibson@gmail.com>

* Update test/intl402/DateTimeFormat/constructor-invalid-offset-timezone.js

Co-authored-by: Richard Gibson <richard.gibson@gmail.com>

* Update test/intl402/DateTimeFormat/constructor-invalid-offset-timezone.js

Co-authored-by: Richard Gibson <richard.gibson@gmail.com>

* Update test/intl402/DateTimeFormat/prototype/resolvedOptions/offset-timezone-change.js

Co-authored-by: Richard Gibson <richard.gibson@gmail.com>

* Update test/intl402/DateTimeFormat/constructor-invalid-offset-timezone.js

Co-authored-by: Richard Gibson <richard.gibson@gmail.com>

* Update test/intl402/DateTimeFormat/prototype/format/offset-timezone-gmt-same.js

Co-authored-by: Richard Gibson <richard.gibson@gmail.com>

* Update test/intl402/DateTimeFormat/prototype/format/offset-timezone-gmt-same.js

Co-authored-by: Richard Gibson <richard.gibson@gmail.com>

* Update test/intl402/DateTimeFormat/prototype/formatToParts/offset-timezone-correct.js

Co-authored-by: Richard Gibson <richard.gibson@gmail.com>

---------

Co-authored-by: Richard Gibson <richard.gibson@gmail.com>
This commit is contained in:
Frank Yung-Fong Tang 2023-09-26 09:22:50 -07:00 committed by GitHub
parent b5fd799fa0
commit 6789b50cce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 152 additions and 0 deletions

View File

@ -0,0 +1,36 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-createdatetimeformat
description: Tests that invalid offset time zones are rejected.
---*/
let invalidOffsetTimeZones = [
'+3',
'+24',
'+23:0',
'+130',
'+13234',
'+135678',
'-7',
'-10.50',
'-10,50',
'-24',
'-014',
'-210',
'-2400',
'-1:10',
'-21:0',
'+0:003',
'+15:59:00',
'+15:59.50',
'+15:59,50',
'+222700',
'-02:3200',
'-170100',
'-22230',
];
invalidOffsetTimeZones.forEach((timeZone) => {
assert.throws(RangeError, function() {
new Intl.DateTimeFormat(undefined, {timeZone});
}, timeZone + ":");
});

View File

@ -0,0 +1,27 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-createdatetimeformat
description: >
Tests that date and time formatting in an offset time zone
matches that in the equivalent Etc/GMT±n time zone.
---*/
let offsetTimeZones = {
'+0300': 'Etc/GMT-3',
'+1400': 'Etc/GMT-14',
'+02': 'Etc/GMT-2',
'+13:00': 'Etc/GMT-13',
'-07:00': 'Etc/GMT+7',
'-12': 'Etc/GMT+12',
'0900': 'Etc/GMT+9',
'10:00': 'Etc/GMT+10',
'0500': 'Etc/GMT+5',
};
let date = new Date('1995-12-17T03:24:56Z');
Object.entries(offsetTimeZones).forEach(([offsetZone, gmtZone]) => {
let offsetDf = new Intl.DateTimeFormat("en",
{timeZone: offsetZone, dateStyle: "short", timeStyle: "short"});
let gmtDf = new Intl.DateTimeFormat("en",
{timeZone: gmtZone, dateStyle: "short", timeStyle: "short"});
assert.sameValue(offsetDf.format(date), gmtDf.format(date), `${offsetZone} vs. ${gmtZone}:`);
});

View File

@ -0,0 +1,28 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-createdatetimeformat
description: >
Tests that formatted hour and minute are correct for offset time zones.
---*/
let date = new Date('1995-12-17T03:24:56Z');
let tests = {
'+0301': {hour: "6", minute: "25"},
'+1412': {hour: "5", minute: "36"},
'+02': {hour: "5", minute: "24"},
'+13:49': {hour: "5", minute: "13"},
'-07:56': {hour: "7", minute: "28"},
'-12': {hour: "3", minute: "24"},
'0914': {hour: "6", minute: "10"},
'10:03': {hour: "5", minute: "21"},
'0509': {hour: "10", minute: "15"},
};
Object.entries(tests).forEach(([timeZone, expected]) => {
let df = new Intl.DateTimeFormat("en",
{timeZone, timeStyle: "short"});
let res = df.formatToParts(date);
let hour = res.filter((t) => t.type === "hour")[0].value
let minute = res.filter((t) => t.type === "minute")[0].value
assert.sameValue(hour, expected.hour, `hour in ${timeZone} time zone:`);
assert.sameValue(minute, expected.minute, `minute in ${timeZone} time zone:`);
});

View File

@ -0,0 +1,28 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-createdatetimeformat
description: Tests that offset time zones are correctly normalized in resolvedOptions() output.
---*/
let validOffsetTimeZones = [
'+03',
'+13',
'+23',
'-07',
'-14',
'-21',
'+01:03',
'+15:59',
'+22:27',
'-02:32',
'-17:01',
'-22:23',
];
validOffsetTimeZones.forEach((timeZone) => {
let df = new Intl.DateTimeFormat(undefined, {timeZone});
let expected = timeZone;
if (expected.length == 3) {
expected += ":00";
}
assert.sameValue(df.resolvedOptions().timeZone, expected, timeZone);
});

View File

@ -0,0 +1,33 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-createdatetimeformat
description: Tests that offset time zones are correctly normalized in resolvedOptions() output.
---*/
let validOffsetTimeZones = {
'-00': '+00:00',
'-00:00': '+00:00',
'00:00': '+00:00',
'+00': '+00:00',
'+0000': '+00:00',
'+0300': '+03:00',
'+03:00': '+03:00',
'+13:00': '+13:00',
'+2300': '+23:00',
'-07:00': '-07:00',
'-14': '-14:00',
'-2100': '-21:00',
'2200': '-22:00',
'+0103': '+01:03',
'+15:59': '+15:59',
'+2227': '+22:27',
'-02:32': '-02:32',
'-1701': '-17:01',
'-22:23': '-22:23',
'22:53': '-22:53',
};
Object.keys(validOffsetTimeZones).forEach((timeZone) => {
let df = new Intl.DateTimeFormat(undefined, {timeZone});
let expected = validOffsetTimeZones[timeZone];
assert.sameValue(df.resolvedOptions().timeZone, expected, timeZone);
});