Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for ECMA402 PR 788 #3917

Merged
merged 14 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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',
FrankYFTang marked this conversation as resolved.
Show resolved Hide resolved
'-10.50',
'-10,50',
'-24',
'-014',
'-210',
'-2400',
'-1:10',
'-21:0',
'+0:003',
'+15:59:00',
FrankYFTang marked this conversation as resolved.
Show resolved Hide resolved
'+15:59.50',
'+15:59,50',
'+222700',
'-02:3200',
'-170100',
'-22230',
];
invalidOffsetTimeZones.forEach((timeZone) => {
assert.throws(RangeError, function() {
new Intl.DateTimeFormat(undefined, {timeZone});
}, timeZone + ":");
});
Original file line number Diff line number Diff line change
@@ -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}:`);
});
Original file line number Diff line number Diff line change
@@ -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:`);
});
Original file line number Diff line number Diff line change
@@ -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);
});
Original file line number Diff line number Diff line change
@@ -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);
});