Debian Codegraph @

js/src/tests/test262/built-ins/Temporal/Duration/compare/relativeto-undefined-throw-on-calendar-units.js

raw
1 // |reftest| shell-option(--enable-temporal) skip-if(!this.hasOwnProperty('Temporal')||!xulRuntime.shell) -- Temporal is not enabled unconditionally, requires shell-options
2 // Copyright (C) 2021 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.duration.compare
7 description: >
8 The relativeTo option is required when either Duration contains years,
9 months, or weeks
10 features: [Temporal]
11 ---*/
12
13 const oneYear = new Temporal.Duration(1);
14 const oneMonth = new Temporal.Duration(0, 1);
15 const oneWeek = new Temporal.Duration(0, 0, 1);
16 const oneDay = new Temporal.Duration(0, 0, 0, 1);
17 const twoDays = new Temporal.Duration(0, 0, 0, 2);
18
19 assert.sameValue(Temporal.Duration.compare(oneDay, twoDays), -1, "days do not require relativeTo");
20
21 assert.throws(RangeError, () => Temporal.Duration.compare(oneWeek, oneDay), "weeks in left operand require relativeTo");
22 assert.throws(RangeError, () => Temporal.Duration.compare(oneDay, oneWeek), "weeks in right operand require relativeTo");
23
24 assert.throws(RangeError, () => Temporal.Duration.compare(oneMonth, oneDay), "months in left operand require relativeTo");
25 assert.throws(RangeError, () => Temporal.Duration.compare(oneDay, oneMonth), "months in right operand require relativeTo");
26
27 assert.throws(RangeError, () => Temporal.Duration.compare(oneYear, oneDay), "years in left operand require relativeTo");
28 assert.throws(RangeError, () => Temporal.Duration.compare(oneDay, oneYear), "years in right operand require relativeTo");
29
30 reportCompare(0, 0);