Skip to content

Commit 9e1758d

Browse files
committed
Limit offset time zones to minute precision
Modify/add tests for tc39/proposal-temporal#2607
1 parent 016e4bf commit 9e1758d

File tree

93 files changed

+681
-378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+681
-378
lines changed

test/built-ins/Temporal/Duration/compare/relativeto-sub-minute-offset.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,25 @@
33

44
/*---
55
esid: sec-temporal.duration.compare
6-
description: relativeTo string accepts an inexact UTC offset rounded to hours and minutes
6+
description: relativeTo string accepts trailing zeroes in sub-minute UTC offset
77
features: [Temporal]
88
---*/
99

1010
const duration1 = new Temporal.Duration(0, 0, 0, 31);
1111
const duration2 = new Temporal.Duration(0, 1);
1212

13-
let relativeTo = "2000-01-01T00:00+00:45[+00:44:30.123456789]";
14-
assert.sameValue(Temporal.Duration.compare(duration1, duration2, { relativeTo }), 0, "rounded HH:MM is accepted in string");
13+
let result;
14+
let relativeTo;
1515

16-
relativeTo = "2000-01-01T00:00+00:44:30[+00:44:30.123456789]";
17-
assert.throws(RangeError, () => Temporal.Duration.compare(duration1, duration2, { relativeTo }), "no other rounding is accepted for offset");
16+
const action = (relativeTo) => Temporal.Duration.compare(duration1, duration2, { relativeTo });
1817

19-
const timeZone = new Temporal.TimeZone("+00:44:30.123456789");
20-
relativeTo = { year: 2000, month: 1, day: 1, offset: "+00:45", timeZone };
21-
assert.throws(RangeError, () => Temporal.Duration.compare(duration1, duration2, { relativeTo }), "rounded HH:MM not accepted as offset in property bag");
18+
relativeTo = "1970-01-01T00:00-00:45:00[-00:45]";
19+
result = action(relativeTo);
20+
assert.sameValue(result, 0, "ISO string offset accepted with zero seconds (string)");
21+
22+
relativeTo = { year: 1970, month: 1, day: 1, offset: "+00:45:00.000000000", timeZone: "+00:45" };
23+
result = action(relativeTo);
24+
assert.sameValue(result, 0, "ISO string offset accepted with zero seconds (property bag)");
25+
26+
relativeTo = "1970-01-01T00:00+00:44:30.123456789[+00:45]";
27+
assert.throws(RangeError, () => action(relativeTo), "rounding is not accepted between ISO offset and time zone");

test/built-ins/Temporal/Duration/prototype/add/relativeto-sub-minute-offset.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33

44
/*---
55
esid: sec-temporal.duration.prototype.add
6-
description: relativeTo string accepts an inexact UTC offset rounded to hours and minutes
6+
description: relativeTo string accepts trailing zeroes in sub-minute UTC offset
77
includes: [temporalHelpers.js]
88
features: [Temporal]
99
---*/
1010

1111
const instance = new Temporal.Duration(1, 0, 0, 1);
12+
let result;
13+
let relativeTo;
14+
const action = (relativeTo) => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo });
1215

13-
let relativeTo = "2000-01-01T00:00+00:45[+00:44:30.123456789]";
14-
const result = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo });
15-
TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "rounded HH:MM is accepted in string");
16+
relativeTo = "1970-01-01T00:00-00:45:00[-00:45]";
17+
result = action(relativeTo);
18+
TemporalHelpers.assertDateDuration(result, 1, 0, 0, 0, "ISO string offset accepted with zero seconds (string)");
1619

17-
relativeTo = "2000-01-01T00:00+00:44:30[+00:44:30.123456789]";
18-
assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), "no other rounding is accepted for offset");
20+
relativeTo = { year: 1970, month: 1, day: 1, offset: "+00:45:00.000000000", timeZone: "+00:45" };
21+
result = action(relativeTo);
22+
TemporalHelpers.assertDateDuration(result, 1, 0, 0, 0, "ISO string offset accepted with zero seconds (property bag)");
1923

20-
const timeZone = new Temporal.TimeZone("+00:44:30.123456789");
21-
relativeTo = { year: 2000, month: 1, day: 1, offset: "+00:45", timeZone };
22-
assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), "rounded HH:MM not accepted as offset in property bag");
24+
relativeTo = "1970-01-01T00:00+00:44:30.123456789[+00:45]";
25+
assert.throws(RangeError, () => action(relativeTo), "rounding is not accepted between ISO offset and time zone");

test/built-ins/Temporal/Duration/prototype/round/relativeto-sub-minute-offset.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,25 @@
33

44
/*---
55
esid: sec-temporal.duration.prototype.round
6-
description: relativeTo string accepts an inexact UTC offset rounded to hours and minutes
6+
description: relativeTo string accepts trailing zeroes in sub-minute UTC offset
77
includes: [temporalHelpers.js]
88
features: [Temporal]
99
---*/
1010

1111
const instance = new Temporal.Duration(1, 0, 0, 0, 24);
1212

13-
let relativeTo = "2000-01-01T00:00+00:45[+00:44:30.123456789]";
14-
const result = instance.round({ largestUnit: "years", relativeTo });
15-
TemporalHelpers.assertDuration(result, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "rounded HH:MM is accepted in string");
13+
let result;
14+
let relativeTo;
1615

17-
relativeTo = "2000-01-01T00:00+00:44:30[+00:44:30.123456789]";
18-
assert.throws(RangeError, () => instance.round({ largestUnit: "years", relativeTo }), "no other rounding is accepted for offset");
16+
const action = (relativeTo) => instance.round({ largestUnit: "years", relativeTo });
1917

20-
const timeZone = new Temporal.TimeZone("+00:44:30.123456789");
21-
relativeTo = { year: 2000, month: 1, day: 1, offset: "+00:45", timeZone };
22-
assert.throws(RangeError, () => instance.round({ largestUnit: "years", relativeTo }), "rounded HH:MM not accepted as offset in property bag");
18+
relativeTo = "1970-01-01T00:00-00:45:00[-00:45]";
19+
result = action(relativeTo);
20+
TemporalHelpers.assertDateDuration(result, 1, 0, 0, 1, "ISO string offset accepted with zero seconds (string)");
21+
22+
relativeTo = { year: 1970, month: 1, day: 1, offset: "+00:45:00.000000000", timeZone: "+00:45" };
23+
result = action(relativeTo);
24+
TemporalHelpers.assertDateDuration(result, 1, 0, 0, 1, "ISO string offset accepted with zero seconds (property bag)");
25+
26+
relativeTo = "1970-01-01T00:00+00:44:30.123456789[+00:45]";
27+
assert.throws(RangeError, () => action(relativeTo), "rounding is not accepted between ISO offset and time zone");

test/built-ins/Temporal/Duration/prototype/subtract/relativeto-sub-minute-offset.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33

44
/*---
55
esid: sec-temporal.duration.prototype.subtract
6-
description: relativeTo string accepts an inexact UTC offset rounded to hours and minutes
6+
description: relativeTo string accepts trailing zeroes in sub-minute UTC offset
77
includes: [temporalHelpers.js]
88
features: [Temporal]
99
---*/
1010

1111
const instance = new Temporal.Duration(1, 0, 0, 1);
1212

13-
let relativeTo = "2000-01-01T00:00+00:45[+00:44:30.123456789]";
14-
const result = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo });
15-
TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "rounded HH:MM is accepted in string");
13+
let result;
14+
let relativeTo;
15+
const action = (relativeTo) => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo });
1616

17-
relativeTo = "2000-01-01T00:00+00:44:30[+00:44:30.123456789]";
18-
assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), "no other rounding is accepted for offset");
17+
relativeTo = "1970-01-01T00:00-00:45:00[-00:45]";
18+
result = action(relativeTo);
19+
TemporalHelpers.assertDateDuration(result, 1, 0, 0, 0, "ISO string offset accepted with zero seconds (string)");
1920

20-
const timeZone = new Temporal.TimeZone("+00:44:30.123456789");
21-
relativeTo = { year: 2000, month: 1, day: 1, offset: "+00:45", timeZone };
22-
assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), "rounded HH:MM not accepted as offset in property bag");
21+
relativeTo = { year: 1970, month: 1, day: 1, offset: "+00:45:00.000000000", timeZone: "+00:45" };
22+
result = action(relativeTo);
23+
TemporalHelpers.assertDateDuration(result, 1, 0, 0, 0, "ISO string offset accepted with zero seconds (property bag)");
24+
25+
relativeTo = "1970-01-01T00:00+00:44:30.123456789[+00:45]";
26+
assert.throws(RangeError, () => action(relativeTo), "rounding is not accepted between ISO offset and time zone");

test/built-ins/Temporal/Duration/prototype/total/relativeto-sub-minute-offset.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@
33

44
/*---
55
esid: sec-temporal.duration.prototype.total
6-
description: relativeTo string accepts an inexact UTC offset rounded to hours and minutes
6+
description: relativeTo string accepts trailing zeroes in sub-minute UTC offset
77
features: [Temporal]
88
---*/
99

1010
const instance = new Temporal.Duration(1, 0, 0, 0, 24);
1111

12-
let relativeTo = "2000-01-01T00:00+00:45[+00:44:30.123456789]";
13-
const result = instance.total({ unit: "days", relativeTo });
14-
assert.sameValue(result, 367, "rounded HH:MM is accepted in string");
12+
let result;
13+
let relativeTo;
1514

16-
relativeTo = "2000-01-01T00:00+00:44:30[+00:44:30.123456789]";
17-
assert.throws(RangeError, () => instance.total({ unit: "days", relativeTo }), "no other rounding is accepted for offset");
15+
const action = (relativeTo) => instance.total({ unit: "days", relativeTo });
1816

19-
const timeZone = new Temporal.TimeZone("+00:44:30.123456789");
20-
relativeTo = { year: 2000, month: 1, day: 1, offset: "+00:45", timeZone };
21-
assert.throws(RangeError, () => instance.total({ unit: "days", relativeTo }), "rounded HH:MM not accepted as offset in property bag");
17+
relativeTo = "1970-01-01T00:00-00:45:00[-00:45]";
18+
result = action(relativeTo);
19+
assert.sameValue(result, 366, "ISO string offset accepted with zero seconds (string)");
20+
21+
relativeTo = { year: 1970, month: 1, day: 1, offset: "+00:45:00.000000000", timeZone: "+00:45" };
22+
result = action(relativeTo);
23+
assert.sameValue(result, 366, "ISO string offset accepted with zero seconds (property bag)");
24+
25+
relativeTo = "1970-01-01T00:00+00:44:30.123456789[+00:45]";
26+
assert.throws(RangeError, () => action(relativeTo), "rounding is not accepted between ISO offset and time zone");

test/built-ins/Temporal/Instant/compare/instant-string-multiple-offsets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ features: [Temporal]
88
---*/
99

1010
const epoch = new Temporal.Instant(0n);
11-
const str = "1970-01-01T00:02:00.000000000+00:02[+00:01:30.987654321]";
11+
const str = "1970-01-01T00:02:00.000000000+00:02[+01:30]";
1212

1313
assert.sameValue(Temporal.Instant.compare(str, epoch), 0, "UTC offset determined from offset part of string (first argument)");
1414
assert.sameValue(Temporal.Instant.compare(epoch, str), 0, "UTC offset determined from offset part of string (second argument)");

test/built-ins/Temporal/Instant/from/instant-string-multiple-offsets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: Instant strings with UTC offset fractional part are not confused wi
77
features: [Temporal]
88
---*/
99

10-
const str = "1970-01-01T00:02:00.000000000+00:02[+00:01:30.987654321]";
10+
const str = "1970-01-01T00:02:00.000000000+00:02[+01:30]";
1111

1212
const result = Temporal.Instant.from(str);
1313
assert.sameValue(result.epochNanoseconds, 0n, "UTC offset determined from offset part of string");

test/built-ins/Temporal/Instant/prototype/equals/instant-string-multiple-offsets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ features: [Temporal]
88
---*/
99

1010
const instance = new Temporal.Instant(0n);
11-
const str = "1970-01-01T00:02:00.000000000+00:02[+00:01:30.987654321]";
11+
const str = "1970-01-01T00:02:00.000000000+00:02[+01:30]";
1212

1313
const result = instance.equals(str);
1414
assert.sameValue(result, true, "UTC offset determined from offset part of string");

test/built-ins/Temporal/Instant/prototype/since/instant-string-multiple-offsets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ features: [Temporal]
99
---*/
1010

1111
const instance = new Temporal.Instant(0n);
12-
const str = "1970-01-01T00:02:00.000000000+00:02[+00:01:30.987654321]";
12+
const str = "1970-01-01T00:02:00.000000000+00:02[+01:30]";
1313

1414
const result = instance.since(str);
1515
TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "UTC offset determined from offset part of string");

test/built-ins/Temporal/Instant/prototype/toString/timezone-offset.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,3 @@ function test(timeZoneIdentifier, expected, description) {
1717
test("UTC", "1970-01-01T00:00:00+00:00", "offset of UTC is +00:00");
1818
test("+01:00", "1970-01-01T01:00:00+01:00", "positive offset");
1919
test("-05:00", "1969-12-31T19:00:00-05:00", "negative offset");
20-
test("+00:44:59.123456789", "1970-01-01T00:44:59.123456789+00:45", "sub-minute offset");
21-
test("-00:00:10.987654321", "1969-12-31T23:59:49.012345679+00:00", "sub-minute offset that rounds to zero");

0 commit comments

Comments
 (0)