Skip to content

Commit 2bae86b

Browse files
ioannadMs2ger
authored andcommitted
[Temporal] Test that fractional minutes or hours in time string throws a RangeError.
Time strings such as "05:07.123" (fractional minutes) and "12.5" (fractional hours) should throw a RangeError. This addresses proposal-temporal issue: tc39/proposal-temporal#3210 The tests pass in the polyfill with the fix in proposal-temporal PR: tc39/proposal-temporal#3236
1 parent d6b05b1 commit 2bae86b

32 files changed

+741
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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.duration.compare
6+
description: Fractional minutes or hours in time string in relativeTo option should throw RangeError
7+
features: [Temporal]
8+
---*/
9+
10+
const instance1 = new Temporal.Duration(1, 0, 0, 0, 24)
11+
const instance2 = new Temporal.Duration(1, 0, 0, 0, 24)
12+
13+
const invalidStrings = [
14+
["2025-04-03T05:07.123", "Fractional minutes"],
15+
["2025-04-03T12.5", "Fractional hours"],
16+
];
17+
18+
for (const [arg, description] of invalidStrings) {
19+
assert.throws(
20+
RangeError,
21+
() => Temporal.Duration.compare(instance1, instance2, { relativeTo: arg }),
22+
`${description} not allowed in time string`
23+
);
24+
}
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.duration.prototype.round
6+
description: Fractional minutes or hours in time string in relativeTo option should throw RangeError
7+
features: [Temporal]
8+
---*/
9+
10+
const instance = new Temporal.Duration(1, 0, 0, 0, 24)
11+
12+
const invalidStrings = [
13+
["2025-04-03T05:07.123", "Fractional minutes"],
14+
["2025-04-03T12.5", "Fractional hours"],
15+
];
16+
17+
for (const [arg, description] of invalidStrings) {
18+
assert.throws(
19+
RangeError,
20+
() => instance.round({ largestUnit: "months", relativeTo: arg }),
21+
`${description} not allowed in time string`
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.duration.prototype.total
6+
description: Fractional minutes or hours in time string in relativeTo option should throw RangeError
7+
features: [Temporal]
8+
---*/
9+
10+
const instance = new Temporal.Duration(1, 0, 0, 0, 24)
11+
12+
const invalidStrings = [
13+
["2025-04-03T05:07.123", "Fractional minutes"],
14+
["2025-04-03T12.5", "Fractional hours"],
15+
];
16+
17+
for (const [arg, description] of invalidStrings) {
18+
assert.throws(
19+
RangeError,
20+
() => instance.total({ unit: "months", relativeTo: arg }),
21+
`${description} not allowed in time string`
22+
);
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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: Fractional minutes or hours in time string should throw RangeError
7+
features: [Temporal]
8+
---*/
9+
10+
const invalidStrings = [
11+
["2025-04-03T05:07.123[CET]", "Fractional minutes"],
12+
["2025-04-03T12.5[CET]", "Fractional hours"],
13+
];
14+
15+
for (const [arg, description] of invalidStrings) {
16+
assert.throws(
17+
RangeError,
18+
() => Temporal.Instant.compare(arg, new Temporal.Instant(0n)),
19+
`${description} not allowed in time string (first argument)`
20+
);
21+
assert.throws(
22+
RangeError,
23+
() => Temporal.Instant.compare(new Temporal.Instant(0n), arg),
24+
`${description} not allowed in time string (second argument)`
25+
);
26+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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: Fractional minutes or hours in time string should throw RangeError
7+
features: [Temporal]
8+
---*/
9+
10+
const invalidStrings = [
11+
["2025-04-03T05:07.123[CET]", "Fractional minutes"],
12+
["2025-04-03T12.5[CET]", "Fractional hours"],
13+
];
14+
15+
for (const [arg, description] of invalidStrings) {
16+
assert.throws(
17+
RangeError,
18+
() => Temporal.Instant.from(arg),
19+
`${description} not allowed in time string`
20+
);
21+
}
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: Fractional minutes or hours in time string should throw RangeError
7+
features: [Temporal]
8+
---*/
9+
10+
const instance = new Temporal.Instant(0n)
11+
12+
const invalidStrings = [
13+
["2025-04-03T05:07.123[CET]", "Fractional minutes"],
14+
["2025-04-03T12.5[CET]", "Fractional hours"],
15+
];
16+
17+
for (const [arg, description] of invalidStrings) {
18+
assert.throws(
19+
RangeError,
20+
() => instance.equals(arg),
21+
`${description} not allowed in time string`
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: Fractional minutes or hours in time string should throw RangeError
7+
features: [Temporal]
8+
---*/
9+
10+
const instance = new Temporal.Instant(0n)
11+
12+
const invalidStrings = [
13+
["2025-04-03T05:07.123[CET]", "Fractional minutes"],
14+
["2025-04-03T12.5[CET]", "Fractional hours"],
15+
];
16+
17+
for (const [arg, description] of invalidStrings) {
18+
assert.throws(
19+
RangeError,
20+
() => instance.since(arg),
21+
`${description} not allowed in time string`
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: Fractional minutes or hours in time string should throw RangeError
7+
features: [Temporal]
8+
---*/
9+
10+
const instance = new Temporal.Instant(0n)
11+
12+
const invalidStrings = [
13+
["2025-04-03T05:07.123[CET]", "Fractional minutes"],
14+
["2025-04-03T12.5[CET]", "Fractional hours"],
15+
];
16+
17+
for (const [arg, description] of invalidStrings) {
18+
assert.throws(
19+
RangeError,
20+
() => instance.until(arg),
21+
`${description} not allowed in time string`
22+
);
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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: Fractional minutes or hours in time string should throw RangeError
7+
features: [Temporal]
8+
---*/
9+
10+
const invalidStrings = [
11+
["2025-04-03T05:07.123", "Fractional minutes"],
12+
["2025-04-03T12.5", "Fractional hours"],
13+
];
14+
15+
for (const [arg, description] of invalidStrings) {
16+
assert.throws(
17+
RangeError,
18+
() => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(2025, 04, 03)),
19+
`${description} not allowed in time string (first argument)`
20+
);
21+
assert.throws(
22+
RangeError,
23+
() => Temporal.PlainDate.compare(new Temporal.PlainDate(2025, 04, 03), arg),
24+
`${description} not allowed in time string (second argument)`
25+
);
26+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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: Fractional minutes or hours in time string should throw RangeError
7+
features: [Temporal]
8+
---*/
9+
10+
const invalidStrings = [
11+
["2025-04-03T05:07.123", "Fractional minutes"],
12+
["2025-04-03T12.5", "Fractional hours"],
13+
];
14+
15+
for (const [arg, description] of invalidStrings) {
16+
assert.throws(
17+
RangeError,
18+
() => Temporal.PlainDate.from(arg),
19+
`${description} not allowed in time string`
20+
);
21+
}

0 commit comments

Comments
 (0)