Skip to content

Commit ad06578

Browse files
ptomatoMs2ger
authored andcommitted
Editorial: Correctly parse relativeTo string
A string given as the value of the relativeTo option must be parsed as a Temporal.ZonedDateTime if possible, and otherwise as a PlainDateTime. This is hopefully an editorial change, because the spec text as written was unimplementable. There were no [[TimeZoneOffset]] or [[TimeZoneIANAName]] fields on the Record returned from ParseISODateTime. Closes: #1738
1 parent cd8b317 commit ad06578

22 files changed

+352
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (C) 2021 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: RangeError thrown if relativeTo is a string with the wrong format
7+
features: [Temporal]
8+
---*/
9+
10+
['bad string', '15:30:45.123456', 'iso8601', 'UTC', 'P1YT1H'].forEach((relativeTo) => {
11+
const duration1 = new Temporal.Duration(0, 0, 0, 31);
12+
const duration2 = new Temporal.Duration(0, 1);
13+
assert.throws(RangeError, () => Temporal.Duration.compare(duration1, duration2, { relativeTo }));
14+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (C) 2021 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: The relativeTo option accepts a PlainDateTime-like ISO 8601 string
7+
features: [Temporal]
8+
---*/
9+
10+
['2000-01-01', '2000-01-01T00:00', '2000-01-01T00:00[u-ca=iso8601]'].forEach((relativeTo) => {
11+
const duration1 = new Temporal.Duration(0, 0, 0, 31);
12+
const duration2 = new Temporal.Duration(0, 1);
13+
const result = Temporal.Duration.compare(duration1, duration2, { relativeTo });
14+
assert.sameValue(result, 0);
15+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (C) 2021 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: RangeError thrown if relativeTo is an ISO 8601 string with a Z as the time zone designator
7+
features: [Temporal]
8+
---*/
9+
10+
['2000-01-01T00:00Z', '2000-01-01T00:00Z[UTC]'].forEach((relativeTo) => {
11+
const duration1 = new Temporal.Duration(0, 0, 0, 31);
12+
const duration2 = new Temporal.Duration(0, 1);
13+
assert.throws(RangeError, () => Temporal.Duration.compare(duration1, duration2, { relativeTo }));
14+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (C) 2021 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: The relativeTo option accepts a ZonedDateTime-like ISO 8601 string
7+
features: [Temporal]
8+
includes: [temporalHelpers.js]
9+
---*/
10+
11+
[
12+
'2000-01-01[UTC]',
13+
'2000-01-01T00:00[UTC]',
14+
'2000-01-01T00:00+00:00[UTC]',
15+
'2000-01-01T00:00+00:00[UTC][u-ca=iso8601]',
16+
].forEach((relativeTo) => {
17+
const duration1 = new Temporal.Duration(0, 0, 0, 31);
18+
const duration2 = new Temporal.Duration(0, 1);
19+
const result = Temporal.Duration.compare(duration1, duration2, { relativeTo });
20+
assert.sameValue(result, 0);
21+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (C) 2021 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.add
6+
description: RangeError thrown if relativeTo is a string with the wrong format
7+
features: [Temporal]
8+
---*/
9+
10+
['bad string', '15:30:45.123456', 'iso8601', 'UTC', 'P1YT1H'].forEach((relativeTo) => {
11+
const duration = new Temporal.Duration(1, 0, 0, 15);
12+
assert.throws(RangeError, () => duration.add(new Temporal.Duration(0, 0, 0, 16), { relativeTo }));
13+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (C) 2021 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.add
6+
description: The relativeTo option accepts a PlainDateTime-like ISO 8601 string
7+
features: [Temporal]
8+
includes: [temporalHelpers.js]
9+
---*/
10+
11+
['2000-01-01', '2000-01-01T00:00', '2000-01-01T00:00[u-ca=iso8601]'].forEach((relativeTo) => {
12+
const duration = new Temporal.Duration(1, 0, 0, 15);
13+
const result = duration.add(new Temporal.Duration(0, 0, 0, 16), { relativeTo });
14+
TemporalHelpers.assertDuration(result, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0);
15+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (C) 2021 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.add
6+
description: RangeError thrown if relativeTo is an ISO 8601 string with a Z as the time zone designator
7+
features: [Temporal]
8+
---*/
9+
10+
['2000-01-01T00:00Z', '2000-01-01T00:00Z[UTC]'].forEach((relativeTo) => {
11+
const duration = new Temporal.Duration(1, 0, 0, 15);
12+
assert.throws(RangeError, () => duration.add(new Temporal.Duration(0, 0, 0, 16), { relativeTo }));
13+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (C) 2021 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.add
6+
description: The relativeTo option accepts a ZonedDateTime-like ISO 8601 string
7+
features: [Temporal]
8+
includes: [temporalHelpers.js]
9+
---*/
10+
11+
[
12+
'2000-01-01[UTC]',
13+
'2000-01-01T00:00[UTC]',
14+
'2000-01-01T00:00+00:00[UTC]',
15+
'2000-01-01T00:00+00:00[UTC][u-ca=iso8601]',
16+
].forEach((relativeTo) => {
17+
const duration = new Temporal.Duration(1, 0, 0, 15);
18+
const result = duration.add(new Temporal.Duration(0, 0, 0, 16), { relativeTo });
19+
TemporalHelpers.assertDuration(result, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0);
20+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (C) 2021 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: RangeError thrown if relativeTo is a string with the wrong format
7+
features: [Temporal]
8+
---*/
9+
10+
['bad string', '15:30:45.123456', 'iso8601', 'UTC', 'P1YT1H'].forEach((relativeTo) => {
11+
const duration = new Temporal.Duration(0, 0, 0, 31);
12+
assert.throws(RangeError, () => duration.round({ largestUnit: "months", relativeTo }));
13+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (C) 2021 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: The relativeTo option accepts a PlainDateTime-like ISO 8601 string
7+
features: [Temporal]
8+
includes: [temporalHelpers.js]
9+
---*/
10+
11+
['2000-01-01', '2000-01-01T00:00', '2000-01-01T00:00[u-ca=iso8601]'].forEach((relativeTo) => {
12+
const duration = new Temporal.Duration(0, 0, 0, 31);
13+
const result = duration.round({ largestUnit: "months", relativeTo });
14+
TemporalHelpers.assertDuration(result, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0);
15+
});

0 commit comments

Comments
 (0)