mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
Temporal: Move tests for ZonedDateTime/p/{add, subtract} out of staging into test/built-ins (#4287)
This commit is contained in:
parent
febf246e05
commit
85934bf49c
17
test/built-ins/Temporal/ZonedDateTime/prototype/add/add-duration.js
vendored
Normal file
17
test/built-ins/Temporal/ZonedDateTime/prototype/add/add-duration.js
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright (C) 2023 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: Adding a duration object works.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// "1969-12-25T12:23:45.678901234+00:00[UTC]"
|
||||
const zdt = new Temporal.ZonedDateTime(-560174321098766n, "UTC")
|
||||
const d = new Temporal.Duration(0, 0, 0, 0, 240, 0, 0, 0, 0, 800);
|
||||
// "1970-01-04T12:23:45.678902034+00:00[UTC]"
|
||||
const expected = new Temporal.ZonedDateTime(303825678902034n, "UTC");
|
||||
|
||||
TemporalHelpers.assertZonedDateTimesEqual(zdt.add(d), expected);
|
16
test/built-ins/Temporal/ZonedDateTime/prototype/add/casts-argument.js
vendored
Normal file
16
test/built-ins/Temporal/ZonedDateTime/prototype/add/casts-argument.js
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright (C) 2023 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: Casts argument to Duration.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// "1969-12-25T12:23:45.678901234+00:00[UTC]"
|
||||
const zdt = new Temporal.ZonedDateTime(-560174321098766n, "UTC")
|
||||
// "1970-01-04T12:23:45.678902034+00:00[UTC]"
|
||||
const expected = new Temporal.ZonedDateTime(303825678902034n, "UTC");
|
||||
|
||||
TemporalHelpers.assertZonedDateTimesEqual(zdt.add("PT240H0.000000800S"), expected);
|
18
test/built-ins/Temporal/ZonedDateTime/prototype/add/constrain-when-ambiguous-result.js
vendored
Normal file
18
test/built-ins/Temporal/ZonedDateTime/prototype/add/constrain-when-ambiguous-result.js
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright (C) 2023 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: Constrains result when ambiguous.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// "2020-01-31T15:00-08:00[-08:00]"
|
||||
const jan31 = new Temporal.ZonedDateTime(1580511600000000000n, "-08:00");
|
||||
// "2020-02-29T15:00:00-08:00[-08:00]"
|
||||
const expected = new Temporal.ZonedDateTime(1583017200000000000n, "-08:00");
|
||||
|
||||
TemporalHelpers.assertZonedDateTimesEqual(jan31.add({ months: 1 }), expected);
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
jan31.add({ months: 1 }, { overflow: "constrain" }), expected);
|
39
test/built-ins/Temporal/ZonedDateTime/prototype/add/cross-epoch.js
vendored
Normal file
39
test/built-ins/Temporal/ZonedDateTime/prototype/add/cross-epoch.js
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2023 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: Cross-epoch add/subtract
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// "1969-12-25T12:23:45.678901234+00:00[UTC]"
|
||||
const zdt = new Temporal.ZonedDateTime(-560174321098766n, "UTC")
|
||||
|
||||
// cross epoch in ms
|
||||
var one = zdt.subtract({
|
||||
hours: 240,
|
||||
nanoseconds: 800
|
||||
});
|
||||
var two = zdt.add({
|
||||
hours: 240,
|
||||
nanoseconds: 800
|
||||
});
|
||||
var three = two.subtract({
|
||||
hours: 480,
|
||||
nanoseconds: 1600
|
||||
});
|
||||
var four = one.add({
|
||||
hours: 480,
|
||||
nanoseconds: 1600
|
||||
});
|
||||
|
||||
TemporalHelpers.assertZonedDateTimesEqual(one,
|
||||
// "1969-12-15T12:23:45.678900434+00:00[UTC]"
|
||||
new Temporal.ZonedDateTime(-1424174321099566n, "UTC"));
|
||||
TemporalHelpers.assertZonedDateTimesEqual(two,
|
||||
// "1970-01-04T12:23:45.678902034+00:00[UTC]")
|
||||
new Temporal.ZonedDateTime(303825678902034n, "UTC"));
|
||||
TemporalHelpers.assertZonedDateTimesEqual(three, one);
|
||||
TemporalHelpers.assertZonedDateTimesEqual(four, two);
|
@ -0,0 +1,19 @@
|
||||
// Copyright (C) 2023 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: Results are symmetrical with regard to negative durations in the time part.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// "2020-01-31T15:00-08:00[-08:00]"
|
||||
const jan31 = new Temporal.ZonedDateTime(1580511600000000000n, "-08:00");
|
||||
// "2020-01-31T14:30:00-08:00[-08:00]"
|
||||
const expected1 = new Temporal.ZonedDateTime(1580509800000000000n, "-08:00");
|
||||
// "2020-01-31T14:59:30-08:00[-08:00]"
|
||||
const expected2 = new Temporal.ZonedDateTime(1580511570000000000n, "-08:00");
|
||||
|
||||
TemporalHelpers.assertZonedDateTimesEqual(jan31.add({ minutes: -30 }), expected1);
|
||||
TemporalHelpers.assertZonedDateTimesEqual(jan31.add({ seconds: -30 }), expected2);
|
13
test/built-ins/Temporal/ZonedDateTime/prototype/add/throw-when-ambiguous-result-with-reject.js
vendored
Normal file
13
test/built-ins/Temporal/ZonedDateTime/prototype/add/throw-when-ambiguous-result-with-reject.js
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright (C) 2023 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: Throws when ambiguous result with reject
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// "2020-01-31T15:00-08:00[-08:00]"
|
||||
const jan31 = new Temporal.ZonedDateTime(1580511600000000000n, "-08:00");
|
||||
|
||||
assert.throws(RangeError, () => jan31.add({ months: 1 }, { overflow: "reject" }));
|
15
test/built-ins/Temporal/ZonedDateTime/prototype/subtract/casts-argument.js
vendored
Normal file
15
test/built-ins/Temporal/ZonedDateTime/prototype/subtract/casts-argument.js
vendored
Normal 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.subtract
|
||||
description: Casts argument from string.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const zdt = Temporal.ZonedDateTime.from("1969-12-25T12:23:45.678901234+00:00[UTC]");
|
||||
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
zdt.subtract("PT240H0.000000800S"),
|
||||
Temporal.ZonedDateTime.from("1969-12-15T12:23:45.678900434+00:00[UTC]"));
|
21
test/built-ins/Temporal/ZonedDateTime/prototype/subtract/constrain-when-ambiguous-result.js
vendored
Normal file
21
test/built-ins/Temporal/ZonedDateTime/prototype/subtract/constrain-when-ambiguous-result.js
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
// 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.subtract
|
||||
description: Constrains when ambiguous result.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const mar31 = Temporal.ZonedDateTime.from("2020-03-31T15:00+00:00[UTC]");
|
||||
const expected = Temporal.ZonedDateTime.from("2020-02-29T15:00:00+00:00[UTC]");
|
||||
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
mar31.subtract({ months: 1 }),
|
||||
expected);
|
||||
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
mar31.subtract({ months: 1 }, { overflow: "constrain" }),
|
||||
expected);
|
||||
|
17
test/built-ins/Temporal/ZonedDateTime/prototype/subtract/subtract-duration-object.js
vendored
Normal file
17
test/built-ins/Temporal/ZonedDateTime/prototype/subtract/subtract-duration-object.js
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// 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.subtract
|
||||
description: Can subtract a duration object.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const zdt = Temporal.ZonedDateTime.from("1969-12-25T12:23:45.678901234+00:00[UTC]");
|
||||
const d = new Temporal.Duration(0, 0, 0, 0, 240, 0, 0, 0, 0, 800);
|
||||
|
||||
const earlier = zdt.subtract(d);
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
earlier,
|
||||
Temporal.ZonedDateTime.from("1969-12-15T12:23:45.678900434+00:00[UTC]"));
|
19
test/built-ins/Temporal/ZonedDateTime/prototype/subtract/symmetrical-wrt-negative-durations.js
vendored
Normal file
19
test/built-ins/Temporal/ZonedDateTime/prototype/subtract/symmetrical-wrt-negative-durations.js
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
// 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.subtract
|
||||
description: Symmetrical with regard to negative durations in the time part.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const mar31 = Temporal.ZonedDateTime.from("2020-03-31T15:00+00:00[UTC]");
|
||||
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
mar31.subtract({ minutes: -30 }),
|
||||
Temporal.ZonedDateTime.from("2020-03-31T15:30:00+00:00[UTC]"));
|
||||
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
mar31.subtract({ seconds: -30 }),
|
||||
Temporal.ZonedDateTime.from("2020-03-31T15:00:30+00:00[UTC]"));
|
@ -0,0 +1,12 @@
|
||||
// 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.subtract
|
||||
description: Throws on an ambiguous result with reject.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const mar31 = Temporal.ZonedDateTime.from("2020-03-31T15:00+00:00[UTC]");
|
||||
|
||||
assert.throws(RangeError, () => mar31.subtract({ months: 1 }, { overflow: "reject" }));
|
@ -1,50 +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: Temporal.ZonedDateTime.prototype.add()
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var zdt = Temporal.ZonedDateTime.from("1969-12-25T12:23:45.678901234+00:00[UTC]");
|
||||
// cross epoch in ms
|
||||
var one = zdt.subtract({
|
||||
hours: 240,
|
||||
nanoseconds: 800
|
||||
});
|
||||
var two = zdt.add({
|
||||
hours: 240,
|
||||
nanoseconds: 800
|
||||
});
|
||||
var three = two.subtract({
|
||||
hours: 480,
|
||||
nanoseconds: 1600
|
||||
});
|
||||
var four = one.add({
|
||||
hours: 480,
|
||||
nanoseconds: 1600
|
||||
});
|
||||
assert.sameValue(`${ one }`, "1969-12-15T12:23:45.678900434+00:00[UTC]");
|
||||
assert.sameValue(`${ two }`, "1970-01-04T12:23:45.678902034+00:00[UTC]");
|
||||
assert(three.equals(one));
|
||||
assert(four.equals(two));
|
||||
|
||||
// zdt.add(durationObj)
|
||||
var later = zdt.add(Temporal.Duration.from("PT240H0.000000800S"));
|
||||
assert.sameValue(`${ later }`, "1970-01-04T12:23:45.678902034+00:00[UTC]");
|
||||
|
||||
// casts argument
|
||||
assert.sameValue(`${ zdt.add("PT240H0.000000800S") }`, "1970-01-04T12:23:45.678902034+00:00[UTC]");
|
||||
var jan31 = Temporal.ZonedDateTime.from("2020-01-31T15:00-08:00[-08:00]");
|
||||
|
||||
// constrain when ambiguous result
|
||||
assert.sameValue(`${ jan31.add({ months: 1 }) }`, "2020-02-29T15:00:00-08:00[-08:00]");
|
||||
assert.sameValue(`${ jan31.add({ months: 1 }, { overflow: "constrain" }) }`, "2020-02-29T15:00:00-08:00[-08:00]");
|
||||
|
||||
// symmetrical with regard to negative durations in the time part
|
||||
assert.sameValue(`${ jan31.add({ minutes: -30 }) }`, "2020-01-31T14:30:00-08:00[-08:00]");
|
||||
assert.sameValue(`${ jan31.add({ seconds: -30 }) }`, "2020-01-31T14:59:30-08:00[-08:00]");
|
||||
|
||||
// throw when ambiguous result with reject
|
||||
assert.throws(RangeError, () => jan31.add({ months: 1 }, { overflow: "reject" }));
|
@ -1,29 +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: Temporal.ZonedDateTime.prototype.subtract()
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var zdt = Temporal.ZonedDateTime.from("1969-12-25T12:23:45.678901234+00:00[UTC]");
|
||||
|
||||
// inst.subtract(durationObj)
|
||||
var earlier = zdt.subtract(Temporal.Duration.from("PT240H0.000000800S"));
|
||||
assert.sameValue(`${ earlier }`, "1969-12-15T12:23:45.678900434+00:00[UTC]");
|
||||
|
||||
// casts argument
|
||||
assert.sameValue(`${ zdt.subtract("PT240H0.000000800S") }`, "1969-12-15T12:23:45.678900434+00:00[UTC]");
|
||||
var mar31 = Temporal.ZonedDateTime.from("2020-03-31T15:00+00:00[UTC]");
|
||||
|
||||
// constrain when ambiguous result
|
||||
assert.sameValue(`${ mar31.subtract({ months: 1 }) }`, "2020-02-29T15:00:00+00:00[UTC]");
|
||||
assert.sameValue(`${ mar31.subtract({ months: 1 }, { overflow: "constrain" }) }`, "2020-02-29T15:00:00+00:00[UTC]");
|
||||
|
||||
// symmetrical with regard to negative durations in the time part
|
||||
assert.sameValue(`${ mar31.subtract({ minutes: -30 }) }`, "2020-03-31T15:30:00+00:00[UTC]");
|
||||
assert.sameValue(`${ mar31.subtract({ seconds: -30 }) }`, "2020-03-31T15:00:30+00:00[UTC]");
|
||||
|
||||
// throw when ambiguous result with reject
|
||||
assert.throws(RangeError, () => mar31.subtract({ months: 1 }, { overflow: "reject" }));
|
Loading…
x
Reference in New Issue
Block a user