Skip to content

Commit

Permalink
Add test for ECMA402 PR 788
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankYFTang authored and ptomato committed Sep 26, 2023
1 parent b5fd799 commit 810011d
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/intl402/DateTimeFormat/constructor-invalid-offset-timezone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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: test invalid offset timezone will throw.
---*/
let invalidOffsetTimeZones = [
'+3',
'+24',
'+23:0',
'+130',
'+13234',
'+135678',
'-7',
'-24',
'-014',
'-210',
'-2400',
'-1:10',
'-21:0',
'+0:003',
'+15:59:00',
'+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,26 @@
// 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: test offset timezone format the same value as the equivalent
Etc/GMT offset timezone
---*/
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.keys(offsetTimeZones).forEach((timeZone) => {
let offsetDf = new Intl.DateTimeFormat("en",
{timeZone, dateStyle: "short", timeStyle: "short"});
let gmtDf = new Intl.DateTimeFormat("en",
{timeZone: offsetTimeZones[timeZone], dateStyle: "short", timeStyle: "short"});
assert.sameValue(offsetDf.format(date), gmtDf.format(date));
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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: test offset timezone generate the correct hour and minute
base on the offset timezone value.
---*/
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.keys(tests).forEach((timeZone) => {
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
let expected = tests[timeZone];
assert.sameValue(expected.hour, hour, "hour in TimeZone:" + timeZone);
assert.sameValue(expected.minute, minute, "minute in TimeZone:" + timeZone);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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: test offset timezone with sign sync with resolvedOptions().timeZone.
---*/
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 actual = df.resolvedOptions().timeZone;
assert.sameValue(timeZone, actual);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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: test offset timezone with sign sync with resolvedOptions().timeZone.
---*/
let validOffsetTimeZones = {
'+0300': '+03',
'+0300': '+03',
'+13:00': '+13',
'+2300': '+23',
'-07:00': '-07',
'-14': '-14',
'-2100': '-21',
'−2200': '-22',
'+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 actual = df.resolvedOptions().timeZone;
let expected = validOffsetTimeZones[timeZone];
assert.sameValue(expected, actual);
});

0 comments on commit 810011d

Please sign in to comment.