Skip to content

Commit 454ba1f

Browse files
ptomatoMs2ger
authored andcommitted
Temporal: Test that strings with >9 decimal places are rejected
Up to 9 decimal places are supported. 10 are not. Test this with both a nonzero and zero tenth decimal digit, and in both times and UTC offsets where applicable. This was a bug in V8 and Boa. See boa-dev/temporal#677
1 parent ab1590d commit 454ba1f

File tree

36 files changed

+895
-0
lines changed

36 files changed

+895
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (C) 2026 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.instant.compare
6+
description: No more than 9 decimal places are allowed
7+
features: [Temporal]
8+
---*/
9+
10+
var invalidStrings = [
11+
"1970-01-01T00:00:00.1234567891Z",
12+
"1970-01-01T00:00:00.1234567890Z",
13+
"1970-01-01T00+00:00:00.1234567891",
14+
"1970-01-01T00+00:00:00.1234567890",
15+
];
16+
17+
var epoch = new Temporal.Instant(0n);
18+
invalidStrings.forEach(function (arg) {
19+
assert.throws(
20+
RangeError,
21+
function() { Temporal.Instant.compare(arg, epoch); },
22+
"no more than 9 decimal places are allowed (first arg)"
23+
);
24+
assert.throws(
25+
RangeError,
26+
function() { Temporal.Instant.compare(epoch, arg); },
27+
"no more than 9 decimal places are allowed (second arg)"
28+
);
29+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (C) 2026 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.instant.from
6+
description: No more than 9 decimal places are allowed
7+
features: [Temporal]
8+
---*/
9+
10+
var invalidStrings = [
11+
"1970-01-01T00:00:00.1234567891Z",
12+
"1970-01-01T00:00:00.1234567890Z",
13+
"1970-01-01T00+00:00:00.1234567891",
14+
"1970-01-01T00+00:00:00.1234567890",
15+
];
16+
17+
invalidStrings.forEach(function (arg) {
18+
assert.throws(
19+
RangeError,
20+
function() { Temporal.Instant.from(arg); },
21+
"no more than 9 decimal places are allowed"
22+
);
23+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (C) 2026 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.instant.prototype.equals
6+
description: No more than 9 decimal places are allowed
7+
features: [Temporal]
8+
---*/
9+
10+
var invalidStrings = [
11+
"1970-01-01T00:00:00.1234567891Z",
12+
"1970-01-01T00:00:00.1234567890Z",
13+
"1970-01-01T00+00:00:00.1234567891",
14+
"1970-01-01T00+00:00:00.1234567890",
15+
];
16+
var instance = new Temporal.Instant(0n);
17+
invalidStrings.forEach(function (arg) {
18+
assert.throws(
19+
RangeError,
20+
function() { instance.equals(arg); },
21+
"no more than 9 decimal places are allowed"
22+
);
23+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (C) 2026 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.instant.prototype.since
6+
description: No more than 9 decimal places are allowed
7+
features: [Temporal]
8+
---*/
9+
10+
var invalidStrings = [
11+
"1970-01-01T00:00:00.1234567891Z",
12+
"1970-01-01T00:00:00.1234567890Z",
13+
"1970-01-01T00+00:00:00.1234567891",
14+
"1970-01-01T00+00:00:00.1234567890",
15+
];
16+
var instance = new Temporal.Instant(0n);
17+
invalidStrings.forEach(function (arg) {
18+
assert.throws(
19+
RangeError,
20+
function() { instance.since(arg); },
21+
"no more than 9 decimal places are allowed"
22+
);
23+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (C) 2026 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.instant.prototype.until
6+
description: No more than 9 decimal places are allowed
7+
features: [Temporal]
8+
---*/
9+
10+
var invalidStrings = [
11+
"1970-01-01T00:00:00.1234567891Z",
12+
"1970-01-01T00:00:00.1234567890Z",
13+
"1970-01-01T00+00:00:00.1234567891",
14+
"1970-01-01T00+00:00:00.1234567890",
15+
];
16+
var instance = new Temporal.Instant(0n);
17+
invalidStrings.forEach(function (arg) {
18+
assert.throws(
19+
RangeError,
20+
function() { instance.until(arg); },
21+
"no more than 9 decimal places are allowed"
22+
);
23+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (C) 2026 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.plaindate.compare
6+
description: No more than 9 decimal places are allowed
7+
features: [Temporal]
8+
---*/
9+
10+
var invalidStrings = [
11+
"1970-01-01T00:00:00.1234567891",
12+
"1970-01-01T00:00:00.1234567890",
13+
"1970-01-01T00+00:00:00.1234567891",
14+
"1970-01-01T00+00:00:00.1234567890",
15+
];
16+
17+
invalidStrings.forEach(function (arg) {
18+
assert.throws(
19+
RangeError,
20+
function() { Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)); },
21+
"no more than 9 decimal places are allowed (first arg)"
22+
);
23+
assert.throws(
24+
RangeError,
25+
function() { Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg); },
26+
"no more than 9 decimal places are allowed (second arg)"
27+
);
28+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (C) 2026 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.plaindate.from
6+
description: No more than 9 decimal places are allowed
7+
features: [Temporal]
8+
---*/
9+
10+
var invalidStrings = [
11+
"1970-01-01T00:00:00.1234567891",
12+
"1970-01-01T00:00:00.1234567890",
13+
"1970-01-01T00+00:00:00.1234567891",
14+
"1970-01-01T00+00:00:00.1234567890",
15+
];
16+
17+
invalidStrings.forEach(function (arg) {
18+
assert.throws(
19+
RangeError,
20+
function() { Temporal.PlainDate.from(arg); },
21+
"no more than 9 decimal places are allowed"
22+
);
23+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (C) 2026 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.plaindate.prototype.equals
6+
description: No more than 9 decimal places are allowed
7+
features: [Temporal]
8+
---*/
9+
10+
var invalidStrings = [
11+
"1970-01-01T00:00:00.1234567891",
12+
"1970-01-01T00:00:00.1234567890",
13+
"1970-01-01T00+00:00:00.1234567891",
14+
"1970-01-01T00+00:00:00.1234567890",
15+
];
16+
var instance = new Temporal.PlainDate(2000, 5, 2);
17+
invalidStrings.forEach(function (arg) {
18+
assert.throws(
19+
RangeError,
20+
function() { instance.equals(arg); },
21+
"no more than 9 decimal places are allowed"
22+
);
23+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (C) 2026 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.plaindate.prototype.since
6+
description: No more than 9 decimal places are allowed
7+
features: [Temporal]
8+
---*/
9+
10+
var invalidStrings = [
11+
"1970-01-01T00:00:00.1234567891",
12+
"1970-01-01T00:00:00.1234567890",
13+
"1970-01-01T00+00:00:00.1234567891",
14+
"1970-01-01T00+00:00:00.1234567890",
15+
];
16+
var instance = new Temporal.PlainDate(2000, 5, 2);
17+
invalidStrings.forEach(function (arg) {
18+
assert.throws(
19+
RangeError,
20+
function() { instance.since(arg); },
21+
"no more than 9 decimal places are allowed"
22+
);
23+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (C) 2026 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.plaindate.prototype.toplaindatetime
6+
description: No more than 9 decimal places are allowed
7+
features: [Temporal]
8+
---*/
9+
10+
var invalidStrings = [
11+
"1970-01-01T00:00:00.1234567891",
12+
"1970-01-01T00:00:00.1234567890",
13+
"1970-01-01T00+00:00:00.1234567891",
14+
"1970-01-01T00+00:00:00.1234567890",
15+
"00:00:00.1234567891",
16+
"00:00:00.1234567890",
17+
"00+00:00:00.1234567891",
18+
"00+00:00:00.1234567890",
19+
];
20+
var instance = new Temporal.PlainDate(2000, 5, 2);
21+
invalidStrings.forEach(function (arg) {
22+
assert.throws(
23+
RangeError,
24+
function() { instance.toPlainDateTime(arg); },
25+
"no more than 9 decimal places are allowed"
26+
);
27+
});

0 commit comments

Comments
 (0)