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