Temporal: Move ZonedDateTime order-of-operations tests out of staging

This commit is contained in:
Tim Chevalier 2024-10-29 13:26:01 -07:00 committed by Philip Chimento
parent bf46ed66b6
commit 0f6b269400
7 changed files with 156 additions and 79 deletions

View File

@ -0,0 +1,31 @@
// 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.zoneddatetime.prototype.add
description: Math order of operations - add / constrain.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const breakoutUnits = (op, zdt, d, options) => zdt[op]({ years: d.years }, options)[op]({ months: d.months }, options)[op]({ weeks: d.weeks }, options)[op]({ days: d.days }, options)[op]({
hours: d.hours,
minutes: d.minutes,
seconds: d.seconds,
milliseconds: d.milliseconds,
microseconds: d.microseconds,
nanoseconds: d.nanoseconds
}, options);
// const zdt = Temporal.ZonedDateTime.from("2020-01-31T00:00-08:00[-08:00]");
const zdt = new Temporal.ZonedDateTime(1580457600000000000n, "-08:00");
const d = new Temporal.Duration(0, 1, 0, 1, 0, 0, 0, 0, 0, 0);
// "2020-03-01T00:00:00-08:00[-08:00]"
const expected = new Temporal.ZonedDateTime(1583049600000000000n, "-08:00");
const options = { overflow: "constrain" };
const result = zdt.add(d, options);
TemporalHelpers.assertZonedDateTimesEqual(result, expected);
TemporalHelpers.assertZonedDateTimesEqual(breakoutUnits("add", zdt, d, options), result);

View File

@ -0,0 +1,32 @@
// 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.zoneddatetime.prototype.add
description: Math order of operations - add / none.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const breakoutUnits = (op, zdt, d, options) => zdt[op]({ years: d.years }, options)[op]({ months: d.months }, options)[op]({ weeks: d.weeks }, options)[op]({ days: d.days }, options)[op]({
hours: d.hours,
minutes: d.minutes,
seconds: d.seconds,
milliseconds: d.milliseconds,
microseconds: d.microseconds,
nanoseconds: d.nanoseconds
}, options);
// const zdt = Temporal.ZonedDateTime.from("2020-01-31T00:00-08:00[-08:00]");
const zdt = new Temporal.ZonedDateTime(1580457600000000000n, "-08:00");
const d = new Temporal.Duration(0, 1, 0, 1, 0, 0, 0, 0, 0, 0);
// "2020-03-01T00:00:00-08:00[-08:00]"
const expected = new Temporal.ZonedDateTime(1583049600000000000n, "-08:00");
const options = undefined;
const result = zdt.add(d, options);
TemporalHelpers.assertZonedDateTimesEqual(result, expected);
TemporalHelpers.assertZonedDateTimesEqual(breakoutUnits("add", zdt, d, options),
result);

View File

@ -0,0 +1,16 @@
// 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.zoneddatetime.prototype.add
description: Math order of operations - add / reject.
features: [Temporal]
---*/
// const zdt = Temporal.ZonedDateTime.from("2020-01-31T00:00-08:00[-08:00]");
const zdt = new Temporal.ZonedDateTime(1580457600000000000n, "-08:00");
const d = new Temporal.Duration(0, 1, 0, 1, 0, 0, 0, 0, 0, 0);
const options = { overflow: "reject" };
assert.throws(RangeError, () => zdt.add(d, options));

View File

@ -0,0 +1,31 @@
// 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.zoneddatetime.prototype.add
description: Math order of operations - add / reject.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const breakoutUnits = (op, zdt, d, options) => zdt[op]({ years: d.years }, options)[op]({ months: d.months }, options)[op]({ weeks: d.weeks }, options)[op]({ days: d.days }, options)[op]({
hours: d.hours,
minutes: d.minutes,
seconds: d.seconds,
milliseconds: d.milliseconds,
microseconds: d.microseconds,
nanoseconds: d.nanoseconds
}, options);
// const zdt = Temporal.ZonedDateTime.from("2020-03-31T00:00-08:00[-08:00]");
const zdt = new Temporal.ZonedDateTime(1585641600000000000n, "-08:00");
const d = new Temporal.Duration(0, 1, 0, 1, 0, 0, 0, 0, 0, 0);
const options = { overflow: "constrain" };
// "2020-02-28T00:00:00-08:00[-08:00]"
const expected = new Temporal.ZonedDateTime(1582876800000000000n, "-08:00");
const result = zdt.subtract(d, options);
TemporalHelpers.assertZonedDateTimesEqual(result, expected);
TemporalHelpers.assertZonedDateTimesEqual(breakoutUnits("subtract", zdt, d, options),
result);

View File

@ -0,0 +1,31 @@
// 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.zoneddatetime.prototype.add
description: Math order of operations - add / reject.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const breakoutUnits = (op, zdt, d, options) => zdt[op]({ years: d.years }, options)[op]({ months: d.months }, options)[op]({ weeks: d.weeks }, options)[op]({ days: d.days }, options)[op]({
hours: d.hours,
minutes: d.minutes,
seconds: d.seconds,
milliseconds: d.milliseconds,
microseconds: d.microseconds,
nanoseconds: d.nanoseconds
}, options);
// const zdt = Temporal.ZonedDateTime.from("2020-03-31T00:00-08:00[-08:00]");
const zdt = new Temporal.ZonedDateTime(1585641600000000000n, "-08:00");
const d = new Temporal.Duration(0, 1, 0, 1, 0, 0, 0, 0, 0, 0);
const options = undefined;
// "2020-02-28T00:00:00-08:00[-08:00]"
const expected = new Temporal.ZonedDateTime(1582876800000000000n, "-08:00");
const result = zdt.subtract(d, options);
TemporalHelpers.assertZonedDateTimesEqual(result, expected);
TemporalHelpers.assertZonedDateTimesEqual(breakoutUnits("subtract", zdt, d, options),
result);

View File

@ -0,0 +1,15 @@
// 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.zoneddatetime.prototype.add
description: Math order of operations - add / reject.
features: [Temporal]
---*/
// const zdt = Temporal.ZonedDateTime.from("2020-03-31T00:00-08:00[-08:00]");
const zdt = new Temporal.ZonedDateTime(1585641600000000000n, "-08:00");
const d = new Temporal.Duration(0, 1, 0, 1, 0, 0, 0, 0, 0, 0);
const options = { overflow: "reject" };
assert.throws(RangeError, () => zdt.subtract(d, options));

View File

@ -1,79 +0,0 @@
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal-zoneddatetime-objects
description: math order of operations and options
features: [Temporal]
---*/
var breakoutUnits = (op, zdt, d, options) => zdt[op]({ years: d.years }, options)[op]({ months: d.months }, options)[op]({ weeks: d.weeks }, options)[op]({ days: d.days }, options)[op]({
hours: d.hours,
minutes: d.minutes,
seconds: d.seconds,
milliseconds: d.milliseconds,
microseconds: d.microseconds,
nanoseconds: d.nanoseconds
}, options);
// order of operations: add / none
var zdt = Temporal.ZonedDateTime.from("2020-01-31T00:00-08:00[-08:00]");
var d = Temporal.Duration.from({
months: 1,
days: 1
});
var options = undefined;
var result = zdt.add(d, options);
assert.sameValue(result.toString(), "2020-03-01T00:00:00-08:00[-08:00]");
assert.sameValue(breakoutUnits("add", zdt, d, options).toString(), result.toString());
// order of operations: add / constrain
var zdt = Temporal.ZonedDateTime.from("2020-01-31T00:00-08:00[-08:00]");
var d = Temporal.Duration.from({
months: 1,
days: 1
});
var options = { overflow: "constrain" };
var result = zdt.add(d, options);
assert.sameValue(result.toString(), "2020-03-01T00:00:00-08:00[-08:00]");
assert.sameValue(breakoutUnits("add", zdt, d, options).toString(), result.toString());
// order of operations: add / reject
var zdt = Temporal.ZonedDateTime.from("2020-01-31T00:00-08:00[-08:00]");
var d = Temporal.Duration.from({
months: 1,
days: 1
});
var options = { overflow: "reject" };
assert.throws(RangeError, () => zdt.add(d, options));
// order of operations: subtract / none
var zdt = Temporal.ZonedDateTime.from("2020-03-31T00:00-08:00[-08:00]");
var d = Temporal.Duration.from({
months: 1,
days: 1
});
var options = undefined;
var result = zdt.subtract(d, options);
assert.sameValue(result.toString(), "2020-02-28T00:00:00-08:00[-08:00]");
assert.sameValue(breakoutUnits("subtract", zdt, d, options).toString(), result.toString());
// order of operations: subtract / constrain
var zdt = Temporal.ZonedDateTime.from("2020-03-31T00:00-08:00[-08:00]");
var d = Temporal.Duration.from({
months: 1,
days: 1
});
var options = { overflow: "constrain" };
var result = zdt.subtract(d, options);
assert.sameValue(result.toString(), "2020-02-28T00:00:00-08:00[-08:00]");
assert.sameValue(breakoutUnits("subtract", zdt, d, options).toString(), result.toString());
// order of operations: subtract / reject
var zdt = Temporal.ZonedDateTime.from("2020-03-31T00:00-08:00[-08:00]");
var d = Temporal.Duration.from({
months: 1,
days: 1
});
var options = { overflow: "reject" };
assert.throws(RangeError, () => zdt.subtract(d, options));