forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5fd799
commit 810011d
Showing
5 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
test/intl402/DateTimeFormat/constructor-invalid-offset-timezone.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + ":"); | ||
}); |
26 changes: 26 additions & 0 deletions
26
test/intl402/DateTimeFormat/prototype/format/offset-timezone-gmt-same.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); |
29 changes: 29 additions & 0 deletions
29
test/intl402/DateTimeFormat/prototype/formatToParts/offset-timezone-correct.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
25 changes: 25 additions & 0 deletions
25
test/intl402/DateTimeFormat/prototype/resolvedOptions/offset-timezone-basic.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
29 changes: 29 additions & 0 deletions
29
test/intl402/DateTimeFormat/prototype/resolvedOptions/offset-timezone-change.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |