diff --git a/test/built-ins/Temporal/Duration/compare/relativeto-string-limits.js b/test/built-ins/Temporal/Duration/compare/relativeto-string-limits.js new file mode 100644 index 00000000000..7af8066ec50 --- /dev/null +++ b/test/built-ins/Temporal/Duration/compare/relativeto-string-limits.js @@ -0,0 +1,48 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.compare +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(); + +const validStrings = [ + "-271821-04-20T00:00Z[UTC]", + "+275760-09-13T00:00Z[UTC]", + "+275760-09-13T01:00+01:00[+01:00]", + "+275760-09-13T23:59+23:59[+23:59]", + "-271821-04-19", + "-271821-04-19T01:00", + "+275760-09-13", + "+275760-09-13T23:00", +]; + +for (const relativeTo of validStrings) { + Temporal.Duration.compare(instance, instance, { relativeTo }); +} + +const invalidStrings = [ + "-271821-04-19T23:00-01:00[-01:00]", + "-271821-04-19T00:01-23:59[-23:59]", + "-271821-04-19T23:59:59.999999999Z[UTC]", + "-271821-04-19T23:00-00:59[-00:59]", + "-271821-04-19T00:00:00-23:59[-23:59]", + "+275760-09-13T00:00:00.000000001Z[UTC]", + "+275760-09-13T01:00+00:59[+00:59]", + "+275760-09-14T00:00+23:59[+23:59]", + "-271821-04-18", + "-271821-04-18T23:00", + "+275760-09-14", + "+275760-09-14T01:00", +]; + +for (const relativeTo of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.Duration.compare(instance, instance, { relativeTo }), + `"${relativeTo}" is outside the representable range for a relativeTo parameter` + ); +} diff --git a/test/built-ins/Temporal/Duration/prototype/round/relativeto-string-limits.js b/test/built-ins/Temporal/Duration/prototype/round/relativeto-string-limits.js new file mode 100644 index 00000000000..b9e94e9fad1 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/round/relativeto-string-limits.js @@ -0,0 +1,48 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.round +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(); + +const validStrings = [ + "-271821-04-20T00:00Z[UTC]", + "+275760-09-13T00:00Z[UTC]", + "+275760-09-13T01:00+01:00[+01:00]", + "+275760-09-13T23:59+23:59[+23:59]", + "-271821-04-19", + "-271821-04-19T01:00", + "+275760-09-13", + "+275760-09-13T23:00", +]; + +for (const relativeTo of validStrings) { + instance.round({ smallestUnit: "minutes", relativeTo }); +} + +const invalidStrings = [ + "-271821-04-19T23:00-01:00[-01:00]", + "-271821-04-19T00:01-23:59[-23:59]", + "-271821-04-19T23:59:59.999999999Z[UTC]", + "-271821-04-19T23:00-00:59[-00:59]", + "-271821-04-19T00:00:00-23:59[-23:59]", + "+275760-09-13T00:00:00.000000001Z[UTC]", + "+275760-09-13T01:00+00:59[+00:59]", + "+275760-09-14T00:00+23:59[+23:59]", + "-271821-04-18", + "-271821-04-18T23:00", + "+275760-09-14", + "+275760-09-14T01:00", +]; + +for (const relativeTo of invalidStrings) { + assert.throws( + RangeError, + () => instance.round({ smallestUnit: "minutes", relativeTo }), + `"${relativeTo}" is outside the representable range for a relativeTo parameter` + ); +} diff --git a/test/built-ins/Temporal/Duration/prototype/total/relativeto-string-limits.js b/test/built-ins/Temporal/Duration/prototype/total/relativeto-string-limits.js new file mode 100644 index 00000000000..99e72e764c4 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/total/relativeto-string-limits.js @@ -0,0 +1,48 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.total +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(); + +const validStrings = [ + "-271821-04-20T00:00Z[UTC]", + "+275760-09-13T00:00Z[UTC]", + "+275760-09-13T01:00+01:00[+01:00]", + "+275760-09-13T23:59+23:59[+23:59]", + "-271821-04-19", + "-271821-04-19T01:00", + "+275760-09-13", + "+275760-09-13T23:00", +]; + +for (const relativeTo of validStrings) { + instance.total({ unit: "minutes", relativeTo }); +} + +const invalidStrings = [ + "-271821-04-19T23:00-01:00[-01:00]", + "-271821-04-19T00:01-23:59[-23:59]", + "-271821-04-19T23:59:59.999999999Z[UTC]", + "-271821-04-19T23:00-00:59[-00:59]", + "-271821-04-19T00:00:00-23:59[-23:59]", + "+275760-09-13T00:00:00.000000001Z[UTC]", + "+275760-09-13T01:00+00:59[+00:59]", + "+275760-09-14T00:00+23:59[+23:59]", + "-271821-04-18", + "-271821-04-18T23:00", + "+275760-09-14", + "+275760-09-14T01:00", +]; + +for (const relativeTo of invalidStrings) { + assert.throws( + RangeError, + () => instance.total({ unit: "minutes", relativeTo }), + `"${relativeTo}" is outside the representable range for a relativeTo parameter` + ); +} diff --git a/test/built-ins/Temporal/Instant/compare/argument-string-limits.js b/test/built-ins/Temporal/Instant/compare/argument-string-limits.js new file mode 100644 index 00000000000..f8e09cb7e43 --- /dev/null +++ b/test/built-ins/Temporal/Instant/compare/argument-string-limits.js @@ -0,0 +1,46 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.compare +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(0n); + +const validStrings = [ + "-271821-04-20T00:00Z", + "-271821-04-19T23:00-01:00", + "-271821-04-19T00:00:00.000000001-23:59:59.999999999", + "+275760-09-13T00:00Z", + "+275760-09-13T01:00+01:00", + "+275760-09-13T23:59:59.999999999+23:59:59.999999999", +]; + +for (const arg of validStrings) { + Temporal.Instant.compare(arg, instance); + Temporal.Instant.compare(instance, arg); +} + +const invalidStrings = [ + "-271821-04-19T23:59:59.999999999Z", + "-271821-04-19T23:00-00:59:59.999999999", + "-271821-04-19T00:00:00-23:59:59.999999999", + "+275760-09-13T00:00:00.000000001Z", + "+275760-09-13T01:00+00:59:59.999999999", + "+275760-09-14T00:00+23:59:59.999999999", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.Instant.compare(arg, instance), + `"${arg}" is outside the representable range of Instant (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.Instant.compare(instance, arg), + `"${arg}" is outside the representable range of Instant (second argument)` + ); +} diff --git a/test/built-ins/Temporal/Instant/compare/instant-string-limits.js b/test/built-ins/Temporal/Instant/compare/instant-string-limits.js deleted file mode 100644 index 569b59025b9..00000000000 --- a/test/built-ins/Temporal/Instant/compare/instant-string-limits.js +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.instant.compare -description: String arguments at the limit of the representable range -features: [Temporal] ----*/ - -const minInstant = new Temporal.Instant(-86400_00000000_000_000_000n); -const maxInstant = new Temporal.Instant(86400_00000000_000_000_000n); - -const minInstantStrings = [ - "-271821-04-20T00:00Z", - "-271821-04-19T23:00-01:00", - "-271821-04-19T00:00:00.000000001-23:59:59.999999999", -]; -for (const str of minInstantStrings) { - assert.sameValue(Temporal.Instant.compare(str, minInstant), 0, `instant string ${str} should be valid (first argument)`); - assert.sameValue(Temporal.Instant.compare(minInstant, str), 0, `instant string ${str} should be valid (second argument)`); -} - -const maxInstantStrings = [ - "+275760-09-13T00:00Z", - "+275760-09-13T01:00+01:00", - "+275760-09-13T23:59:59.999999999+23:59:59.999999999", -]; - -for (const str of maxInstantStrings) { - assert.sameValue(Temporal.Instant.compare(str, maxInstant), 0, `instant string ${str} should be valid (first argument)`); - assert.sameValue(Temporal.Instant.compare(maxInstant, str), 0, `instant string ${str} should be valid (second argument)`); -} - -const outOfRangeInstantStrings = [ - "-271821-04-19T23:59:59.999999999Z", - "-271821-04-19T23:00-00:59:59.999999999", - "-271821-04-19T00:00:00-23:59:59.999999999", - "+275760-09-13T00:00:00.000000001Z", - "+275760-09-13T01:00+00:59:59.999999999", - "+275760-09-14T00:00+23:59:59.999999999", -]; - -for (const str of outOfRangeInstantStrings) { - assert.throws(RangeError, () => Temporal.Instant.compare(str, minInstant), `instant string ${str} should not be valid (first argument)`); - assert.throws(RangeError, () => Temporal.Instant.compare(minInstant, str), `instant string ${str} should not be valid (second argument)`); -} diff --git a/test/built-ins/Temporal/Instant/from/argument-string-limits.js b/test/built-ins/Temporal/Instant/from/argument-string-limits.js new file mode 100644 index 00000000000..95b967d754b --- /dev/null +++ b/test/built-ins/Temporal/Instant/from/argument-string-limits.js @@ -0,0 +1,38 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.from +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const validStrings = [ + "-271821-04-20T00:00Z", + "-271821-04-19T23:00-01:00", + "-271821-04-19T00:00:00.000000001-23:59:59.999999999", + "+275760-09-13T00:00Z", + "+275760-09-13T01:00+01:00", + "+275760-09-13T23:59:59.999999999+23:59:59.999999999", +]; + +for (const arg of validStrings) { + Temporal.Instant.from(arg); +} + +const invalidStrings = [ + "-271821-04-19T23:59:59.999999999Z", + "-271821-04-19T23:00-00:59:59.999999999", + "-271821-04-19T00:00:00-23:59:59.999999999", + "+275760-09-13T00:00:00.000000001Z", + "+275760-09-13T01:00+00:59:59.999999999", + "+275760-09-14T00:00+23:59:59.999999999", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.Instant.from(arg), + `"${arg}" is outside the representable range of Instant` + ); +} diff --git a/test/built-ins/Temporal/Instant/from/instant-string-limits.js b/test/built-ins/Temporal/Instant/from/instant-string-limits.js deleted file mode 100644 index 7dfbe6ae80e..00000000000 --- a/test/built-ins/Temporal/Instant/from/instant-string-limits.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.instant.from -description: String arguments at the limit of the representable range -features: [Temporal] ----*/ - -const minInstant = new Temporal.Instant(-86400_00000000_000_000_000n); -const maxInstant = new Temporal.Instant(86400_00000000_000_000_000n); - -const minInstantStrings = [ - "-271821-04-20T00:00Z", - "-271821-04-19T23:00-01:00", - "-271821-04-19T00:00:00.000000001-23:59:59.999999999", -]; -for (const str of minInstantStrings) { - assert.sameValue(Temporal.Instant.from(str).epochNanoseconds, minInstant.epochNanoseconds, `instant string ${str} should be valid`); -} - -const maxInstantStrings = [ - "+275760-09-13T00:00Z", - "+275760-09-13T01:00+01:00", - "+275760-09-13T23:59:59.999999999+23:59:59.999999999", -]; - -for (const str of maxInstantStrings) { - assert.sameValue(Temporal.Instant.from(str).epochNanoseconds, maxInstant.epochNanoseconds, `instant string ${str} should be valid`); -} - -const outOfRangeInstantStrings = [ - "-271821-04-19T23:59:59.999999999Z", - "-271821-04-19T23:00-00:59:59.999999999", - "-271821-04-19T00:00:00-23:59:59.999999999", - "+275760-09-13T00:00:00.000000001Z", - "+275760-09-13T01:00+00:59:59.999999999", - "+275760-09-14T00:00+23:59:59.999999999", -]; - -for (const str of outOfRangeInstantStrings) { - assert.throws(RangeError, () => Temporal.Instant.from(str), `instant string ${str} should not be valid`); -} diff --git a/test/built-ins/Temporal/Instant/prototype/equals/argument-string-limits.js b/test/built-ins/Temporal/Instant/prototype/equals/argument-string-limits.js new file mode 100644 index 00000000000..a9b50709a38 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/equals/argument-string-limits.js @@ -0,0 +1,40 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.equals +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(0n); + +const validStrings = [ + "-271821-04-20T00:00Z", + "-271821-04-19T23:00-01:00", + "-271821-04-19T00:00:00.000000001-23:59:59.999999999", + "+275760-09-13T00:00Z", + "+275760-09-13T01:00+01:00", + "+275760-09-13T23:59:59.999999999+23:59:59.999999999", +]; + +for (const arg of validStrings) { + instance.equals(arg); +} + +const invalidStrings = [ + "-271821-04-19T23:59:59.999999999Z", + "-271821-04-19T23:00-00:59:59.999999999", + "-271821-04-19T00:00:00-23:59:59.999999999", + "+275760-09-13T00:00:00.000000001Z", + "+275760-09-13T01:00+00:59:59.999999999", + "+275760-09-14T00:00+23:59:59.999999999", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.equals(arg), + `"${arg}" is outside the representable range of Instant` + ); +} diff --git a/test/built-ins/Temporal/Instant/prototype/equals/instant-string-limits.js b/test/built-ins/Temporal/Instant/prototype/equals/instant-string-limits.js deleted file mode 100644 index c02f026bbdf..00000000000 --- a/test/built-ins/Temporal/Instant/prototype/equals/instant-string-limits.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.instant.prototype.equals -description: String arguments at the limit of the representable range -features: [Temporal] ----*/ - -const minInstant = new Temporal.Instant(-86400_00000000_000_000_000n); -const maxInstant = new Temporal.Instant(86400_00000000_000_000_000n); - -const minInstantStrings = [ - "-271821-04-20T00:00Z", - "-271821-04-19T23:00-01:00", - "-271821-04-19T00:00:00.000000001-23:59:59.999999999", -]; -for (const str of minInstantStrings) { - assert.sameValue(minInstant.equals(str), true, `instant string ${str} should be valid`); -} - -const maxInstantStrings = [ - "+275760-09-13T00:00Z", - "+275760-09-13T01:00+01:00", - "+275760-09-13T23:59:59.999999999+23:59:59.999999999", -]; - -for (const str of maxInstantStrings) { - assert.sameValue(maxInstant.equals(str), true, `instant string ${str} should be valid`); -} - -const outOfRangeInstantStrings = [ - "-271821-04-19T23:59:59.999999999Z", - "-271821-04-19T23:00-00:59:59.999999999", - "-271821-04-19T00:00:00-23:59:59.999999999", - "+275760-09-13T00:00:00.000000001Z", - "+275760-09-13T01:00+00:59:59.999999999", - "+275760-09-14T00:00+23:59:59.999999999", -]; - -for (const str of outOfRangeInstantStrings) { - assert.throws(RangeError, () => minInstant.equals(str), `instant string ${str} should not be valid`); -} diff --git a/test/built-ins/Temporal/Instant/prototype/since/argument-string-limits.js b/test/built-ins/Temporal/Instant/prototype/since/argument-string-limits.js new file mode 100644 index 00000000000..02f50706263 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/argument-string-limits.js @@ -0,0 +1,40 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.since +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(0n); + +const validStrings = [ + "-271821-04-20T00:00Z", + "-271821-04-19T23:00-01:00", + "-271821-04-19T00:00:00.000000001-23:59:59.999999999", + "+275760-09-13T00:00Z", + "+275760-09-13T01:00+01:00", + "+275760-09-13T23:59:59.999999999+23:59:59.999999999", +]; + +for (const arg of validStrings) { + instance.since(arg); +} + +const invalidStrings = [ + "-271821-04-19T23:59:59.999999999Z", + "-271821-04-19T23:00-00:59:59.999999999", + "-271821-04-19T00:00:00-23:59:59.999999999", + "+275760-09-13T00:00:00.000000001Z", + "+275760-09-13T01:00+00:59:59.999999999", + "+275760-09-14T00:00+23:59:59.999999999", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.since(arg), + `"${arg}" is outside the representable range of Instant` + ); +} diff --git a/test/built-ins/Temporal/Instant/prototype/since/instant-string-limits.js b/test/built-ins/Temporal/Instant/prototype/since/instant-string-limits.js deleted file mode 100644 index 860599bbce1..00000000000 --- a/test/built-ins/Temporal/Instant/prototype/since/instant-string-limits.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.instant.prototype.since -description: String arguments at the limit of the representable range -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const minInstant = new Temporal.Instant(-86400_00000000_000_000_000n); -const maxInstant = new Temporal.Instant(86400_00000000_000_000_000n); - -const minInstantStrings = [ - "-271821-04-20T00:00Z", - "-271821-04-19T23:00-01:00", - "-271821-04-19T00:00:00.000000001-23:59:59.999999999", -]; -for (const str of minInstantStrings) { - TemporalHelpers.assertDuration(minInstant.since(str), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, `instant string ${str} should be valid`); -} - -const maxInstantStrings = [ - "+275760-09-13T00:00Z", - "+275760-09-13T01:00+01:00", - "+275760-09-13T23:59:59.999999999+23:59:59.999999999", -]; - -for (const str of maxInstantStrings) { - TemporalHelpers.assertDuration(maxInstant.since(str), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, `instant string ${str} should be valid`); -} - -const outOfRangeInstantStrings = [ - "-271821-04-19T23:59:59.999999999Z", - "-271821-04-19T23:00-00:59:59.999999999", - "-271821-04-19T00:00:00-23:59:59.999999999", - "+275760-09-13T00:00:00.000000001Z", - "+275760-09-13T01:00+00:59:59.999999999", - "+275760-09-14T00:00+23:59:59.999999999", -]; - -for (const str of outOfRangeInstantStrings) { - assert.throws(RangeError, () => minInstant.since(str), `instant string ${str} should not be valid`); -} diff --git a/test/built-ins/Temporal/Instant/prototype/until/argument-string-limits.js b/test/built-ins/Temporal/Instant/prototype/until/argument-string-limits.js new file mode 100644 index 00000000000..5e62dd0f323 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/argument-string-limits.js @@ -0,0 +1,40 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.until +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(0n); + +const validStrings = [ + "-271821-04-20T00:00Z", + "-271821-04-19T23:00-01:00", + "-271821-04-19T00:00:00.000000001-23:59:59.999999999", + "+275760-09-13T00:00Z", + "+275760-09-13T01:00+01:00", + "+275760-09-13T23:59:59.999999999+23:59:59.999999999", +]; + +for (const arg of validStrings) { + instance.until(arg); +} + +const invalidStrings = [ + "-271821-04-19T23:59:59.999999999Z", + "-271821-04-19T23:00-00:59:59.999999999", + "-271821-04-19T00:00:00-23:59:59.999999999", + "+275760-09-13T00:00:00.000000001Z", + "+275760-09-13T01:00+00:59:59.999999999", + "+275760-09-14T00:00+23:59:59.999999999", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.until(arg), + `"${arg}" is outside the representable range of Instant` + ); +} diff --git a/test/built-ins/Temporal/Instant/prototype/until/instant-string-limits.js b/test/built-ins/Temporal/Instant/prototype/until/instant-string-limits.js deleted file mode 100644 index 1c96e3d6a75..00000000000 --- a/test/built-ins/Temporal/Instant/prototype/until/instant-string-limits.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.instant.prototype.until -description: String arguments at the limit of the representable range -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const minInstant = new Temporal.Instant(-86400_00000000_000_000_000n); -const maxInstant = new Temporal.Instant(86400_00000000_000_000_000n); - -const minInstantStrings = [ - "-271821-04-20T00:00Z", - "-271821-04-19T23:00-01:00", - "-271821-04-19T00:00:00.000000001-23:59:59.999999999", -]; -for (const str of minInstantStrings) { - TemporalHelpers.assertDuration(minInstant.until(str), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, `instant string ${str} should be valid`); -} - -const maxInstantStrings = [ - "+275760-09-13T00:00Z", - "+275760-09-13T01:00+01:00", - "+275760-09-13T23:59:59.999999999+23:59:59.999999999", -]; - -for (const str of maxInstantStrings) { - TemporalHelpers.assertDuration(maxInstant.until(str), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, `instant string ${str} should be valid`); -} - -const outOfRangeInstantStrings = [ - "-271821-04-19T23:59:59.999999999Z", - "-271821-04-19T23:00-00:59:59.999999999", - "-271821-04-19T00:00:00-23:59:59.999999999", - "+275760-09-13T00:00:00.000000001Z", - "+275760-09-13T01:00+00:59:59.999999999", - "+275760-09-14T00:00+23:59:59.999999999", -]; - -for (const str of outOfRangeInstantStrings) { - assert.throws(RangeError, () => minInstant.until(str), `instant string ${str} should not be valid`); -} diff --git a/test/built-ins/Temporal/PlainDate/compare/argument-string-limits.js b/test/built-ins/Temporal/PlainDate/compare/argument-string-limits.js new file mode 100644 index 00000000000..258a6381b8b --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/compare/argument-string-limits.js @@ -0,0 +1,42 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.compare +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(1976, 11, 18); + +const validStrings = [ + "-271821-04-19", + "-271821-04-19T01:00", + "+275760-09-13", + "+275760-09-13T23:00", +]; + +for (const arg of validStrings) { + Temporal.PlainDate.compare(arg, instance); + Temporal.PlainDate.compare(instance, arg); +} + +const invalidStrings = [ + "-271821-04-18", + "-271821-04-18T23:00", + "+275760-09-14", + "+275760-09-14T01:00", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.PlainDate.compare(arg, instance), + `"${arg}" is outside the representable range of PlainDate (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainDate.compare(instance, arg), + `"${arg}" is outside the representable range of PlainDate (second argument)` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/from/argument-string-limits.js b/test/built-ins/Temporal/PlainDate/from/argument-string-limits.js new file mode 100644 index 00000000000..2e48b3de571 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/from/argument-string-limits.js @@ -0,0 +1,34 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.from +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const validStrings = [ + "-271821-04-19", + "-271821-04-19T01:00", + "+275760-09-13", + "+275760-09-13T23:00", +]; + +for (const arg of validStrings) { + Temporal.PlainDate.from(arg); +} + +const invalidStrings = [ + "-271821-04-18", + "-271821-04-18T23:00", + "+275760-09-14", + "+275760-09-14T01:00", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.PlainDate.from(arg), + `"${arg}" is outside the representable range of PlainDate` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-string-limits.js b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-string-limits.js new file mode 100644 index 00000000000..4af9bcc2d2a --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-string-limits.js @@ -0,0 +1,36 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.equals +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +const validStrings = [ + "-271821-04-19", + "-271821-04-19T01:00", + "+275760-09-13", + "+275760-09-13T23:00", +]; + +for (const arg of validStrings) { + instance.equals(arg); +} + +const invalidStrings = [ + "-271821-04-18", + "-271821-04-18T23:00", + "+275760-09-14", + "+275760-09-14T01:00", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.equals(arg), + `"${arg}" is outside the representable range of PlainDate` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/argument-string-limits.js b/test/built-ins/Temporal/PlainDate/prototype/since/argument-string-limits.js new file mode 100644 index 00000000000..1b2a00b00f6 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/argument-string-limits.js @@ -0,0 +1,36 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +const validStrings = [ + "-271821-04-19", + "-271821-04-19T01:00", + "+275760-09-13", + "+275760-09-13T23:00", +]; + +for (const arg of validStrings) { + instance.since(arg); +} + +const invalidStrings = [ + "-271821-04-18", + "-271821-04-18T23:00", + "+275760-09-14", + "+275760-09-14T01:00", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.since(arg), + `"${arg}" is outside the representable range of PlainDate` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/argument-string-limits.js b/test/built-ins/Temporal/PlainDate/prototype/until/argument-string-limits.js new file mode 100644 index 00000000000..e3ccbc4280b --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/argument-string-limits.js @@ -0,0 +1,36 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.until +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +const validStrings = [ + "-271821-04-19", + "-271821-04-19T01:00", + "+275760-09-13", + "+275760-09-13T23:00", +]; + +for (const arg of validStrings) { + instance.until(arg); +} + +const invalidStrings = [ + "-271821-04-18", + "-271821-04-18T23:00", + "+275760-09-14", + "+275760-09-14T01:00", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.until(arg), + `"${arg}" is outside the representable range of PlainDate` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/compare/argument-string-limits.js b/test/built-ins/Temporal/PlainDateTime/compare/argument-string-limits.js new file mode 100644 index 00000000000..27f1c429e2e --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/compare/argument-string-limits.js @@ -0,0 +1,42 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.compare +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18); + +const validStrings = [ + "-271821-04-19T00:00:00.000000001", + "-271821-04-20", + "+275760-09-13", + "+275760-09-13T23:59:59.999999999", +]; + +for (const arg of validStrings) { + Temporal.PlainDateTime.compare(arg, instance); + Temporal.PlainDateTime.compare(instance, arg); +} + +const invalidStrings = [ + "-271821-04-19", + "-271821-04-19T00:00", + "+275760-09-14", + "+275760-09-14T00:00", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.PlainDateTime.compare(arg, instance), + `"${arg}" is outside the representable range of PlainDateTime (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainDateTime.compare(instance, arg), + `"${arg}" is outside the representable range of PlainDateTime (second argument)` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/from/argument-string-limits.js b/test/built-ins/Temporal/PlainDateTime/from/argument-string-limits.js new file mode 100644 index 00000000000..27e0e380062 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/from/argument-string-limits.js @@ -0,0 +1,34 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.from +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const validStrings = [ + "-271821-04-19T00:00:00.000000001", + "-271821-04-20", + "+275760-09-13", + "+275760-09-13T23:59:59.999999999", +]; + +for (const arg of validStrings) { + Temporal.PlainDateTime.from(arg); +} + +const invalidStrings = [ + "-271821-04-19", + "-271821-04-19T00:00", + "+275760-09-14", + "+275760-09-14T00:00", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.PlainDateTime.from(arg), + `"${arg}" is outside the representable range of PlainDateTime` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-string-limits.js b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-string-limits.js new file mode 100644 index 00000000000..b97fb81b702 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-string-limits.js @@ -0,0 +1,36 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.equals +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23); + +const validStrings = [ + "-271821-04-19T00:00:00.000000001", + "-271821-04-20", + "+275760-09-13", + "+275760-09-13T23:59:59.999999999", +]; + +for (const arg of validStrings) { + instance.equals(arg); +} + +const invalidStrings = [ + "-271821-04-19", + "-271821-04-19T00:00", + "+275760-09-14", + "+275760-09-14T00:00", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.equals(arg), + `"${arg}" is outside the representable range of PlainDateTime` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-string-limits.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-string-limits.js new file mode 100644 index 00000000000..d106122e342 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-string-limits.js @@ -0,0 +1,36 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.since +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23); + +const validStrings = [ + "-271821-04-19T00:00:00.000000001", + "-271821-04-20", + "+275760-09-13", + "+275760-09-13T23:59:59.999999999", +]; + +for (const arg of validStrings) { + instance.since(arg); +} + +const invalidStrings = [ + "-271821-04-19", + "-271821-04-19T00:00", + "+275760-09-14", + "+275760-09-14T00:00", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.since(arg), + `"${arg}" is outside the representable range of PlainDateTime` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-string-limits.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-string-limits.js new file mode 100644 index 00000000000..658cb732553 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-string-limits.js @@ -0,0 +1,36 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.until +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23); + +const validStrings = [ + "-271821-04-19T00:00:00.000000001", + "-271821-04-20", + "+275760-09-13", + "+275760-09-13T23:59:59.999999999", +]; + +for (const arg of validStrings) { + instance.until(arg); +} + +const invalidStrings = [ + "-271821-04-19", + "-271821-04-19T00:00", + "+275760-09-14", + "+275760-09-14T00:00", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.until(arg), + `"${arg}" is outside the representable range of PlainDateTime` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/compare/argument-string-limits.js b/test/built-ins/Temporal/PlainYearMonth/compare/argument-string-limits.js new file mode 100644 index 00000000000..027757e2bd9 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/compare/argument-string-limits.js @@ -0,0 +1,45 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.compare +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(2019, 6); + +const validStrings = [ + "-271821-04", + "-271821-04-01", + "-271821-04-01T00:00", + "+275760-09", + "+275760-09-30", + "+275760-09-30T23:59:59.999999999", +]; + +for (const arg of validStrings) { + Temporal.PlainYearMonth.compare(arg, instance); + Temporal.PlainYearMonth.compare(instance, arg); +} + +const invalidStrings = [ + "-271821-03-31", + "-271821-03-31T23:59:59.999999999", + "+275760-10", + "+275760-10-01", + "+275760-10-01T00:00", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.PlainYearMonth.compare(arg, instance), + `"${arg}" is outside the representable range of PlainYearMonth (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainYearMonth.compare(instance, arg), + `"${arg}" is outside the representable range of PlainYearMonth (second argument)` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/from/argument-string-limits.js b/test/built-ins/Temporal/PlainYearMonth/from/argument-string-limits.js new file mode 100644 index 00000000000..d06ed173c2e --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/from/argument-string-limits.js @@ -0,0 +1,37 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const validStrings = [ + "-271821-04", + "-271821-04-01", + "-271821-04-01T00:00", + "+275760-09", + "+275760-09-30", + "+275760-09-30T23:59:59.999999999", +]; + +for (const arg of validStrings) { + Temporal.PlainYearMonth.from(arg); +} + +const invalidStrings = [ + "-271821-03-31", + "-271821-03-31T23:59:59.999999999", + "+275760-10", + "+275760-10-01", + "+275760-10-01T00:00", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.PlainYearMonth.from(arg), + `"${arg}" is outside the representable range of PlainYearMonth` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-string-limits.js b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-string-limits.js new file mode 100644 index 00000000000..215fe85f88b --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-string-limits.js @@ -0,0 +1,39 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.equals +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(2019, 12); + +const validStrings = [ + "-271821-04", + "-271821-04-01", + "-271821-04-01T00:00", + "+275760-09", + "+275760-09-30", + "+275760-09-30T23:59:59.999999999", +]; + +for (const arg of validStrings) { + instance.equals(arg); +} + +const invalidStrings = [ + "-271821-03-31", + "-271821-03-31T23:59:59.999999999", + "+275760-10", + "+275760-10-01", + "+275760-10-01T00:00", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.equals(arg), + `"${arg}" is outside the representable range of PlainYearMonth` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-string-limits.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-string-limits.js new file mode 100644 index 00000000000..8ebeaf1364f --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-string-limits.js @@ -0,0 +1,45 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.since +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(1970, 1); + +// Note, these limits are different than other PlainYearMonth conversions +// because the difference is taken between the first days of the two months, so +// the first day of the month of the argument must be within the representable +// range + +const validStrings = [ + "-271821-05", + "-271821-05-01", + "-271821-05-01T00:00", + "+275760-09", + "+275760-09-30", + "+275760-09-30T23:59:59.999999999", +]; + +for (const arg of validStrings) { + instance.since(arg); +} + +const invalidStrings = [ + "-271821-04", + "-271821-04-30", + "-271821-04-30T23:59:59.999999999", + "+275760-10", + "+275760-10-01", + "+275760-10-01T00:00", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.since(arg), + `"${arg}" is outside the representable range of PlainYearMonth` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-string-limits.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-string-limits.js new file mode 100644 index 00000000000..b80b0f04e7d --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-string-limits.js @@ -0,0 +1,45 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.until +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(1970, 1); + +// Note, these limits are different than other PlainYearMonth conversions +// because the difference is taken between the first days of the two months, so +// the first day of the month of the argument must be within the representable +// range + +const validStrings = [ + "-271821-05", + "-271821-05-01", + "-271821-05-01T00:00", + "+275760-09", + "+275760-09-30", + "+275760-09-30T23:59:59.999999999", +]; + +for (const arg of validStrings) { + instance.until(arg); +} + +const invalidStrings = [ + "-271821-04", + "-271821-04-30", + "-271821-04-30T23:59:59.999999999", + "+275760-10", + "+275760-10-01", + "+275760-10-01T00:00", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.until(arg), + `"${arg}" is outside the representable range of PlainYearMonth` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/compare/argument-string-limits.js b/test/built-ins/Temporal/ZonedDateTime/compare/argument-string-limits.js new file mode 100644 index 00000000000..b847d38e685 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/compare/argument-string-limits.js @@ -0,0 +1,46 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.compare +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(0n, "UTC"); + +const validStrings = [ + "-271821-04-20T00:00Z[UTC]", + "+275760-09-13T00:00Z[UTC]", + "+275760-09-13T01:00+01:00[+01:00]", + "+275760-09-13T23:59+23:59[+23:59]", +]; + +for (const arg of validStrings) { + Temporal.ZonedDateTime.compare(arg, instance); + Temporal.ZonedDateTime.compare(instance, arg); +} + +const invalidStrings = [ + "-271821-04-19T23:00-01:00[-01:00]", + "-271821-04-19T00:01-23:59[-23:59]", + "-271821-04-19T23:59:59.999999999Z[UTC]", + "-271821-04-19T23:00-00:59[-00:59]", + "-271821-04-19T00:00:00-23:59[-23:59]", + "+275760-09-13T00:00:00.000000001Z[UTC]", + "+275760-09-13T01:00+00:59[+00:59]", + "+275760-09-14T00:00+23:59[+23:59]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.ZonedDateTime.compare(arg, instance), + `"${arg}" is outside the representable range of ZonedDateTime (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.ZonedDateTime.compare(instance, arg), + `"${arg}" is outside the representable range of ZonedDateTime (second argument)` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-string-limits.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-string-limits.js new file mode 100644 index 00000000000..9e37f111aa8 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-string-limits.js @@ -0,0 +1,78 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.from +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +// offset: "use" takes the exact time with the given UTC offset, and so doesn't +// need to compute the UTC epoch nanoseconds at the wall-clock time. +// offset: "ignore" takes the UTC offset from the time zone, which in the case +// of an offset time zone also doesn't need to compute the UTC epoch nanoseconds +// at the wall-clock time. + +const validStringsForOffsetUseIgnore = [ + "-271821-04-20T00:00Z[UTC]", + "-271821-04-19T23:00-01:00[-01:00]", + "-271821-04-19T00:01-23:59[-23:59]", + "+275760-09-13T00:00Z[UTC]", + "+275760-09-13T01:00+01:00[+01:00]", + "+275760-09-13T23:59+23:59[+23:59]", +]; + +for (const offset of ["use", "ignore"]) { + for (const arg of validStringsForOffsetUseIgnore) { + Temporal.ZonedDateTime.from(arg, { offset: "use" }); + } +} + +// Other values for offset need to compute the UTC epoch nanoseconds at the +// wall-clock time, so that can't be outside the representable range even if +// the signified exact time is inside. + +const validStringsForOffsetPreferReject = [ + "-271821-04-20T00:00Z[UTC]", + "+275760-09-13T00:00Z[UTC]", + "+275760-09-13T01:00+01:00[+01:00]", + "+275760-09-13T23:59+23:59[+23:59]", +]; + +const invalidStringsForOffsetPreferReject = [ + "-271821-04-19T23:00-01:00[-01:00]", + "-271821-04-19T00:00:01-23:59[-23:59]", +]; + +for (const offset of ["prefer", "reject"]) { + for (const arg of validStringsForOffsetPreferReject) { + Temporal.ZonedDateTime.from(arg, { offset }); + } + + for (const arg of invalidStringsForOffsetPreferReject) { + assert.throws( + RangeError, + () => Temporal.ZonedDateTime.from(arg, { offset }), + `wall-clock time of "${arg}" is outside the representable range of ZonedDateTime (offset=${offset})` + ); + } +} + +const invalidStrings = [ + "-271821-04-19T23:59:59.999999999Z[UTC]", + "-271821-04-19T23:00-00:59[-00:59]", + "-271821-04-19T00:00:00-23:59[-23:59]", + "+275760-09-13T00:00:00.000000001Z[UTC]", + "+275760-09-13T01:00+00:59[+00:59]", + "+275760-09-14T00:00+23:59[+23:59]", +]; + +for (const offset of ["use", "ignore", "prefer", "reject"]) { + for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.ZonedDateTime.from(arg, { offset }), + `"${arg}" is outside the representable range of ZonedDateTime (offset=${offset})` + ); + } +} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-string-limits.js b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-string-limits.js new file mode 100644 index 00000000000..c6a30021958 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-string-limits.js @@ -0,0 +1,40 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.equals +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(0n, "UTC"); + +const validStrings = [ + "-271821-04-20T00:00Z[UTC]", + "+275760-09-13T00:00Z[UTC]", + "+275760-09-13T01:00+01:00[+01:00]", + "+275760-09-13T23:59+23:59[+23:59]", +]; + +for (const arg of validStrings) { + instance.equals(arg); +} + +const invalidStrings = [ + "-271821-04-19T23:00-01:00[-01:00]", + "-271821-04-19T00:01-23:59[-23:59]", + "-271821-04-19T23:59:59.999999999Z[UTC]", + "-271821-04-19T23:00-00:59[-00:59]", + "-271821-04-19T00:00:00-23:59[-23:59]", + "+275760-09-13T00:00:00.000000001Z[UTC]", + "+275760-09-13T01:00+00:59[+00:59]", + "+275760-09-14T00:00+23:59[+23:59]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.equals(arg), + `"${arg}" is outside the representable range of ZonedDateTime` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-string-limits.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-string-limits.js new file mode 100644 index 00000000000..9675ada1efd --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-string-limits.js @@ -0,0 +1,41 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.since +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const timeZone = "UTC"; +const instance = new Temporal.ZonedDateTime(0n, timeZone); + +const validStrings = [ + "-271821-04-20T00:00Z[UTC]", + "+275760-09-13T00:00Z[UTC]", + "+275760-09-13T01:00+01:00[+01:00]", + "+275760-09-13T23:59+23:59[+23:59]", +]; + +for (const arg of validStrings) { + instance.since(arg); +} + +const invalidStrings = [ + "-271821-04-19T23:00-01:00[-01:00]", + "-271821-04-19T00:01-23:59[-23:59]", + "-271821-04-19T23:59:59.999999999Z[UTC]", + "-271821-04-19T23:00-00:59[-00:59]", + "-271821-04-19T00:00:00-23:59[-23:59]", + "+275760-09-13T00:00:00.000000001Z[UTC]", + "+275760-09-13T01:00+00:59[+00:59]", + "+275760-09-14T00:00+23:59[+23:59]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.since(arg), + `"${arg}" is outside the representable range of ZonedDateTime` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-string-limits.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-string-limits.js new file mode 100644 index 00000000000..57f74dec4f6 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-string-limits.js @@ -0,0 +1,41 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.until +description: ISO strings at the edges of the representable range +features: [Temporal] +---*/ + +const timeZone = "UTC"; +const instance = new Temporal.ZonedDateTime(0n, timeZone); + +const validStrings = [ + "-271821-04-20T00:00Z[UTC]", + "+275760-09-13T00:00Z[UTC]", + "+275760-09-13T01:00+01:00[+01:00]", + "+275760-09-13T23:59+23:59[+23:59]", +]; + +for (const arg of validStrings) { + instance.until(arg); +} + +const invalidStrings = [ + "-271821-04-19T23:00-01:00[-01:00]", + "-271821-04-19T00:01-23:59[-23:59]", + "-271821-04-19T23:59:59.999999999Z[UTC]", + "-271821-04-19T23:00-00:59[-00:59]", + "-271821-04-19T00:00:00-23:59[-23:59]", + "+275760-09-13T00:00:00.000000001Z[UTC]", + "+275760-09-13T01:00+00:59[+00:59]", + "+275760-09-14T00:00+23:59[+23:59]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.until(arg), + `"${arg}" is outside the representable range of ZonedDateTime` + ); +}