Backed out 2 changesets (bug 1888310, bug 1884625) for causing failures on browser_ap...
[gecko.git] / js / src / tests / test262 / built-ins / Temporal / PlainDate / prototype / since / wrapping-at-end-of-month.js
blob11d3bef1b7526554bd079a7c955981b4afb4880e
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
2 // Copyright (C) 2024 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
5 /*---
6 esid: sec-temporal.plaindate.prototype.since
7 description: Tests balancing of days to months at end of month
8 includes: [temporalHelpers.js]
9 features: [Temporal]
10 ---*/
12 // Difference between end of longer month to end of following shorter month
14   const end = new Temporal.PlainDate(1970, 2, 28);
15   for (const largestUnit of ["years", "months"]) {
16     TemporalHelpers.assertDuration(
17       new Temporal.PlainDate(1970, 1, 28).since(end, { largestUnit }),
18       0, -1, 0, 0, 0, 0, 0, 0, 0, 0,
19       "Jan 28th to Feb 28th is one month"
20     );
21     TemporalHelpers.assertDuration(
22       new Temporal.PlainDate(1970, 1, 29).since(end, { largestUnit }),
23       0, 0, 0, -30, 0, 0, 0, 0, 0, 0,
24       "Jan 29th to Feb 28th is 30 days, not one month"
25     );
26     TemporalHelpers.assertDuration(
27       new Temporal.PlainDate(1970, 1, 30).since(end, { largestUnit }),
28       0, 0, 0, -29, 0, 0, 0, 0, 0, 0,
29       "Jan 30th to Feb 28th is 29 days, not one month"
30     );
31     TemporalHelpers.assertDuration(
32       new Temporal.PlainDate(1970, 1, 31).since(end, { largestUnit }),
33       0, 0, 0, -28, 0, 0, 0, 0, 0, 0,
34       "Jan 31st to Feb 28th is 28 days, not one month"
35     );
36   }
39 // Difference between end of leap-year January to end of leap-year February
41   const end = new Temporal.PlainDate(1972, 2, 29);
42   for (const largestUnit of ["years", "months"]) {
43     TemporalHelpers.assertDuration(
44       new Temporal.PlainDate(1972, 1, 29).since(end, { largestUnit }),
45       0, -1, 0, 0, 0, 0, 0, 0, 0, 0,
46       "Jan 29th to Feb 29th is one month"
47     );
48     TemporalHelpers.assertDuration(
49       new Temporal.PlainDate(1972, 1, 30).since(end, { largestUnit }),
50       0, 0, 0, -30, 0, 0, 0, 0, 0, 0,
51       "Jan 30th to Feb 29th is 30 days, not one month"
52     );
53     TemporalHelpers.assertDuration(
54       new Temporal.PlainDate(1972, 1, 31).since(end, { largestUnit }),
55       0, 0, 0, -29, 0, 0, 0, 0, 0, 0,
56       "Jan 31st to Feb 29th is 29 days, not one month"
57     );
58   }
61 // Difference between end of longer month to end of not-immediately-following
62 // shorter month
64   const end = new Temporal.PlainDate(1970, 11, 30);
65   for (const largestUnit of ["years", "months"]) {
66     TemporalHelpers.assertDuration(
67       new Temporal.PlainDate(1970, 8, 30).since(end, { largestUnit }),
68       0, -3, 0, 0, 0, 0, 0, 0, 0, 0,
69       "Aug 30th to Nov 30th is 3 months"
70     );
71     TemporalHelpers.assertDuration(
72       new Temporal.PlainDate(1970, 8, 31).since(end, { largestUnit }),
73       0, -2, 0, -30, 0, 0, 0, 0, 0, 0,
74       "Aug 31st to Nov 30th is 2 months 30 days, not 3 months"
75     );
76   }
79 // Difference between end of longer month in one year to shorter month in
80 // later year
82   const end = new Temporal.PlainDate(1973, 4, 30);
83   TemporalHelpers.assertDuration(
84     new Temporal.PlainDate(1970, 12, 30).since(end, { largestUnit: "months" }),
85     0, -28, 0, 0, 0, 0, 0, 0, 0, 0,
86     "Dec 30th 1970 to Apr 30th 1973 is 28 months"
87   );
88   TemporalHelpers.assertDuration(
89     new Temporal.PlainDate(1970, 12, 30).since(end, { largestUnit: "years" }),
90     -2, -4, 0, 0, 0, 0, 0, 0, 0, 0,
91     "Dec 30th 1970 to Apr 30th 1973 is 2 years, 4 months"
92   );
93   TemporalHelpers.assertDuration(
94     new Temporal.PlainDate(1970, 12, 31).since(end, { largestUnit: "months" }),
95     0, -27, 0, -30, 0, 0, 0, 0, 0, 0,
96     "Dec 30th 1970 to Apr 30th 1973 is 27 months, 30 days, not 28 months"
97   );
98   TemporalHelpers.assertDuration(
99     new Temporal.PlainDate(1970, 12, 31).since(end, { largestUnit: "years" }),
100     -2, -3, 0, -30, 0, 0, 0, 0, 0, 0,
101     "Dec 30th 1970 to Apr 30th 1973 is 2 years, 3 months, 30 days, not 2 years 4 months"
102   );
105 // Difference where months passes through a month that's the same length or
106 // shorter than either the start or end month
108   TemporalHelpers.assertDuration(
109     new Temporal.PlainDate(1970, 1, 29).since(new Temporal.PlainDate(1970, 3, 28), { largestUnit: "months" }),
110     0, -1, 0, -28, 0, 0, 0, 0, 0, 0,
111     "Jan 29th to Mar 28th is 1 month 28 days, not 58 days"
112   );
113   TemporalHelpers.assertDuration(
114     new Temporal.PlainDate(1970, 1, 31).since(new Temporal.PlainDate(1971, 5, 30), { largestUnit: "years" }),
115     -1, -3, 0, -30, 0, 0, 0, 0, 0, 0,
116     "Jan 31st 1970 to May 30th 1971 is 1 year, 3 months, 30 days, not 1 year, 2 months, 60 days"
117   );
120 reportCompare(0, 0);