From bf3efa65fc85c05733c284c8f104f02e759a0a42 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Fri, 7 Oct 2022 11:39:28 -0700 Subject: [PATCH] Temporal: Adjust relativeto-string-datetime tests As of https://github.com/tc39/proposal-temporal/pull/2397 which reached consensus in the August 2022 TC39 meeting, a date-time + Z with no bracket annotation is no longer accepted as a relativeTo parameter; either the Z should be removed or a bracket annotation should be added. This requires adjusting a few existing tests, but doesn't require any new ones. --- .../add/relativeto-string-datetime.js | 22 +++++++++---------- .../round/relativeto-string-datetime.js | 22 +++++++++---------- .../subtract/relativeto-string-datetime.js | 22 +++++++++---------- .../total/relativeto-string-datetime.js | 22 +++++++++---------- 4 files changed, 40 insertions(+), 48 deletions(-) diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-datetime.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-datetime.js index 2f27346f3f5..2172efa6743 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-datetime.js +++ b/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-datetime.js @@ -16,25 +16,23 @@ let relativeTo = "2019-11-01T00:00"; const result1 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); TemporalHelpers.assertDuration(result1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "bare date-time string is a plain relativeTo"); -relativeTo = "2019-11-01T00:00Z"; -const result2 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration(result2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + Z is a plain relativeTo"); - relativeTo = "2019-11-01T00:00-07:00"; -const result3 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration(result3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + offset is a plain relativeTo"); +const result2 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); +TemporalHelpers.assertDuration(result2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + offset is a plain relativeTo"); relativeTo = "2019-11-01T00:00[-07:00]"; -const result4 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration(result4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + IANA annotation is a zoned relativeTo"); +const result3 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); +TemporalHelpers.assertDuration(result3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + IANA annotation is a zoned relativeTo"); relativeTo = "2019-11-01T00:00Z[-07:00]"; -const result5 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration(result5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + Z + IANA annotation is a zoned relativeTo"); +const result4 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); +TemporalHelpers.assertDuration(result4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + Z + IANA annotation is a zoned relativeTo"); relativeTo = "2019-11-01T00:00+00:00[UTC]"; -const result6 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration(result6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + offset + IANA annotation is a zoned relativeTo"); +const result5 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); +TemporalHelpers.assertDuration(result5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + offset + IANA annotation is a zoned relativeTo"); +relativeTo = "2019-11-01T00:00Z"; +assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), "date-time + Z throws without an IANA annotation"); relativeTo = "2019-11-01T00:00+04:15[UTC]"; assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), "date-time + offset + IANA annotation throws if wall time and exact time mismatch"); diff --git a/test/built-ins/Temporal/Duration/prototype/round/relativeto-string-datetime.js b/test/built-ins/Temporal/Duration/prototype/round/relativeto-string-datetime.js index 2585f935794..4993ad1e577 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/relativeto-string-datetime.js +++ b/test/built-ins/Temporal/Duration/prototype/round/relativeto-string-datetime.js @@ -16,25 +16,23 @@ let relativeTo = "2019-11-01T00:00"; const result1 = instance.round({ largestUnit: "years", relativeTo }); TemporalHelpers.assertDuration(result1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "bare date-time string is a plain relativeTo"); -relativeTo = "2019-11-01T00:00Z"; -const result2 = instance.round({ largestUnit: "years", relativeTo }); -TemporalHelpers.assertDuration(result2, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "date-time + Z is a plain relativeTo"); - relativeTo = "2019-11-01T00:00-07:00"; -const result3 = instance.round({ largestUnit: "years", relativeTo }); -TemporalHelpers.assertDuration(result3, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "date-time + offset is a plain relativeTo"); +const result2 = instance.round({ largestUnit: "years", relativeTo }); +TemporalHelpers.assertDuration(result2, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "date-time + offset is a plain relativeTo"); relativeTo = "2019-11-01T00:00[-07:00]"; -const result4 = instance.round({ largestUnit: "years", relativeTo }); -TemporalHelpers.assertDuration(result4, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "date-time + IANA annotation is a zoned relativeTo"); +const result3 = instance.round({ largestUnit: "years", relativeTo }); +TemporalHelpers.assertDuration(result3, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "date-time + IANA annotation is a zoned relativeTo"); relativeTo = "2019-11-01T00:00Z[-07:00]"; -const result5 = instance.round({ largestUnit: "years", relativeTo }); -TemporalHelpers.assertDuration(result5, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "date-time + Z + IANA annotation is a zoned relativeTo"); +const result4 = instance.round({ largestUnit: "years", relativeTo }); +TemporalHelpers.assertDuration(result4, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "date-time + Z + IANA annotation is a zoned relativeTo"); relativeTo = "2019-11-01T00:00+00:00[UTC]"; -const result6 = instance.round({ largestUnit: "years", relativeTo }); -TemporalHelpers.assertDuration(result6, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "date-time + offset + IANA annotation is a zoned relativeTo"); +const result5 = instance.round({ largestUnit: "years", relativeTo }); +TemporalHelpers.assertDuration(result5, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "date-time + offset + IANA annotation is a zoned relativeTo"); +relativeTo = "2019-11-01T00:00Z"; +assert.throws(RangeError, () => instance.round({ largestUnit: "years", relativeTo }), "date-time + Z throws without an IANA annotation"); relativeTo = "2019-11-01T00:00+04:15[UTC]"; assert.throws(RangeError, () => instance.round({ largestUnit: "years", relativeTo }), "date-time + offset + IANA annotation throws if wall time and exact time mismatch"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-datetime.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-datetime.js index 5c21f75693d..e31b31722ca 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-datetime.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-datetime.js @@ -16,25 +16,23 @@ let relativeTo = "2019-11-01T00:00"; const result1 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); TemporalHelpers.assertDuration(result1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "bare date-time string is a plain relativeTo"); -relativeTo = "2019-11-01T00:00Z"; -const result2 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration(result2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + Z is a plain relativeTo"); - relativeTo = "2019-11-01T00:00-07:00"; -const result3 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration(result3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + offset is a plain relativeTo"); +const result2 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); +TemporalHelpers.assertDuration(result2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + offset is a plain relativeTo"); relativeTo = "2019-11-01T00:00[-07:00]"; -const result4 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration(result4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + IANA annotation is a zoned relativeTo"); +const result3 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); +TemporalHelpers.assertDuration(result3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + IANA annotation is a zoned relativeTo"); relativeTo = "2019-11-01T00:00Z[-07:00]"; -const result5 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration(result5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + Z + IANA annotation is a zoned relativeTo"); +const result4 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); +TemporalHelpers.assertDuration(result4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + Z + IANA annotation is a zoned relativeTo"); relativeTo = "2019-11-01T00:00+00:00[UTC]"; -const result6 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration(result6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + offset + IANA annotation is a zoned relativeTo"); +const result5 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); +TemporalHelpers.assertDuration(result5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + offset + IANA annotation is a zoned relativeTo"); +relativeTo = "2019-11-01T00:00Z"; +assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), "date-time + Z throws without an IANA annotation"); relativeTo = "2019-11-01T00:00+04:15[UTC]"; assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), "date-time + offset + IANA annotation throws if wall time and exact time mismatch"); diff --git a/test/built-ins/Temporal/Duration/prototype/total/relativeto-string-datetime.js b/test/built-ins/Temporal/Duration/prototype/total/relativeto-string-datetime.js index d5160ba02d5..7ab80294cc7 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/relativeto-string-datetime.js +++ b/test/built-ins/Temporal/Duration/prototype/total/relativeto-string-datetime.js @@ -15,25 +15,23 @@ let relativeTo = "2019-11-01T00:00"; const result1 = instance.total({ unit: "days", relativeTo }); assert.sameValue(result1, 367, "bare date-time string is a plain relativeTo"); -relativeTo = "2019-11-01T00:00Z"; -const result2 = instance.total({ unit: "days", relativeTo }); -assert.sameValue(result2, 367, "date-time + Z is a plain relativeTo"); - relativeTo = "2019-11-01T00:00-07:00"; -const result3 = instance.total({ unit: "days", relativeTo }); -assert.sameValue(result3, 367, "date-time + offset is a plain relativeTo"); +const result2 = instance.total({ unit: "days", relativeTo }); +assert.sameValue(result2, 367, "date-time + offset is a plain relativeTo"); relativeTo = "2019-11-01T00:00[-07:00]"; -const result4 = instance.total({ unit: "days", relativeTo }); -assert.sameValue(result4, 367, "date-time + IANA annotation is a zoned relativeTo"); +const result3 = instance.total({ unit: "days", relativeTo }); +assert.sameValue(result3, 367, "date-time + IANA annotation is a zoned relativeTo"); relativeTo = "2019-11-01T00:00Z[-07:00]"; -const result5 = instance.total({ unit: "days", relativeTo }); -assert.sameValue(result5, 367, "date-time + Z + IANA annotation is a zoned relativeTo"); +const result4 = instance.total({ unit: "days", relativeTo }); +assert.sameValue(result4, 367, "date-time + Z + IANA annotation is a zoned relativeTo"); relativeTo = "2019-11-01T00:00+00:00[UTC]"; -const result6 = instance.total({ unit: "days", relativeTo }); -assert.sameValue(result6, 367, "date-time + offset + IANA annotation is a zoned relativeTo"); +const result5 = instance.total({ unit: "days", relativeTo }); +assert.sameValue(result5, 367, "date-time + offset + IANA annotation is a zoned relativeTo"); +relativeTo = "2019-11-01T00:00Z"; +assert.throws(RangeError, () => instance.total({ unit: "days", relativeTo }), "date-time + Z throws without an IANA annotation"); relativeTo = "2019-11-01T00:00+04:15[UTC]"; assert.throws(RangeError, () => instance.total({ unit: "days", relativeTo }), "date-time + offset + IANA annotation throws if wall time and exact time mismatch");