1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
// 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.plaindatetime
description: Testing combinations of since, until, add, subtract, and negated
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const earlier = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789);
const later = new Temporal.PlainDateTime(2019, 10, 29, 10, 46, 38, 271, 986, 102);
const units = ["years", "months", "weeks", "days", "hours", "minutes", "seconds"];
units.forEach((largestUnit) => {
const diff = later.since(earlier, { largestUnit });
TemporalHelpers.assertDurationsEqual(
earlier.since(later, { largestUnit }),
diff.negated(),
`(${earlier}).since(${later}) == (${later}).since(${earlier}).negated()`
);
TemporalHelpers.assertDurationsEqual(
earlier.until(later, { largestUnit }),
diff,
`(${earlier}).until(${later}) == (${later}).since(${earlier})`
);
assert.sameValue(
earlier.add(diff).equals(later),
true,
`(${earlier}).add(${diff}) == (${later})`
);
assert.sameValue(
later.subtract(diff).equals(earlier),
true,
`(${later}).subtract(${diff}) == (${earlier})`
);
assert.sameValue(
earlier.subtract(diff.negated()).equals(later),
true,
"symmetrical with regard to negative durations (1)"
);
assert.sameValue(
later.add(diff.negated()).equals(earlier),
true,
"symmetrical with regard to negative durations (2)"
);
});
reportCompare(0, 0);
|