summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Temporal/Calendar/prototype/dateUntil/largest-unit-year.js
blob: fb29a8c4933106cb0ce3c9298408e029369a7dd2 (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar.prototype.dateuntil
description: Temporal.Calendar.prototype.dateUntil with largestUnit is "year"
info: |
  1. Let calendar be the this value.
  2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
  3. Assert: calendar.[[Identifier]] is "iso8601".
  4. Set one to ? ToTemporalDate(one).
  5. Set two to ? ToTemporalDate(two).
  6. Set options to ? GetOptionsObject(options).
  7. Let largestUnit be ? ToLargestTemporalUnit(options, « "hour", "minute", "second", "millisecond", "microsecond", "nanosecond" », "auto", "day").
  8. Let result be ! DifferenceISODate(one.[[ISOYear]], one.[[ISOMonth]], one.[[ISODay]], two.[[ISOYear]], two.[[ISOMonth]], two.[[ISODay]], largestUnit).
  9. Return ? CreateTemporalDuration(result.[[Years]], result.[[Months]], result.[[Weeks]], result.[[Days]], 0, 0, 0, 0, 0, 0).
features: [Temporal]
includes: [temporalHelpers.js]
---*/
let cal = new Temporal.Calendar("iso8601");

["year", "years"].forEach(function(largestUnit) {
  let opt = {largestUnit};
 TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "2021-07-16", opt),
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "same day");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "2021-07-17", opt),
      0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "one day");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "2021-07-23", opt),
      0, 0, 0, 7, 0, 0, 0, 0, 0, 0, "7 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "2021-08-16", opt),
      0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "1 month in same year");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2020-12-16", "2021-01-16", opt),
      0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "1 month in different year");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-01-05", "2021-02-05", opt),
      0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "1 month in same year");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-01-07", "2021-03-07", opt),
      0, 2, 0, 0, 0, 0, 0, 0, 0, 0, "2 month in same year across Feb 28");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "2021-08-17", opt),
      0, 1, 0, 1, 0, 0, 0, 0, 0, 0, "1 month and 1 day in a month with 31 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "2021-08-13", opt),
      0, 0, 0, 28, 0, 0, 0, 0, 0, 0, "28 days roll across a month which has 31 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "2021-09-16", opt),
      0, 2, 0, 0, 0, 0, 0, 0, 0, 0, "2 months with both months which have 31 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "2022-07-16", opt),
      1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "1 year");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "2031-07-16", opt),
      10, 0, 0, 0, 0, 0, 0, 0, 0, 0, "10 years");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "2022-07-19", opt),
      1, 0, 0, 3, 0, 0, 0, 0, 0, 0, "1 year and 3 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "2022-09-19", opt),
      1, 2, 0, 3, 0, 0, 0, 0, 0, 0, "1 year 2 months and 3 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "2031-12-16", opt),
      10, 5, 0, 0, 0, 0, 0, 0, 0, 0, "10 years and 5 months");
  TemporalHelpers.assertDuration(
      cal.dateUntil("1997-12-16", "2021-07-16", opt),
      23, 7, 0, 0, 0, 0, 0, 0, 0, 0, "23 years and 7 months");
  TemporalHelpers.assertDuration(
      cal.dateUntil("1997-07-16", "2021-07-16", opt),
      24, 0, 0, 0, 0, 0, 0, 0, 0, 0, "24 years");
  TemporalHelpers.assertDuration(
      cal.dateUntil("1997-07-16", "2021-07-15", opt),
      23, 11, 0, 29, 0, 0, 0, 0, 0, 0, "23 years, 11 months and 29 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("1997-06-16", "2021-06-15", opt),
      23, 11, 0, 30, 0, 0, 0, 0, 0, 0, "23 years, 11 months and 30 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("1960-02-16", "2020-03-16", opt),
      60, 1, 0, 0, 0, 0, 0, 0, 0, 0, "60 years, 1 month");
  TemporalHelpers.assertDuration(
      cal.dateUntil("1960-02-16", "2021-03-15", opt),
      61, 0, 0, 27, 0, 0, 0, 0, 0, 0, "61 years, 27 days in non leap year");
  TemporalHelpers.assertDuration(
      cal.dateUntil("1960-02-16", "2020-03-15", opt),
      60, 0, 0, 28, 0, 0, 0, 0, 0, 0, "60 years, 28 days in leap year");

  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-03-30", "2021-07-16", opt),
      0, 3, 0, 16, 0, 0, 0, 0, 0, 0, "3 months and 16 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2020-03-30", "2021-07-16", opt),
      1, 3, 0, 16, 0, 0, 0, 0, 0, 0, "1 year, 3 months and 16 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("1960-03-30", "2021-07-16", opt),
      61, 3, 0, 16, 0, 0, 0, 0, 0, 0, "61 years, 3 months and 16 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2019-12-30", "2021-07-16", opt),
      1, 6, 0, 16, 0, 0, 0, 0, 0, 0, "1 year, 6 months and 16 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2020-12-30", "2021-07-16", opt),
      0, 6, 0, 16, 0, 0, 0, 0, 0, 0, "6 months and 16 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("1997-12-30", "2021-07-16", opt),
      23, 6, 0, 16, 0, 0, 0, 0, 0, 0, "23 years, 6 months and 16 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("0001-12-25", "2021-07-16", opt),
      2019, 6, 0, 21, 0, 0, 0, 0, 0, 0, "2019 years, 6 months and 21 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2019-12-30", "2021-03-05", opt),
      1, 2, 0, 5, 0, 0, 0, 0, 0, 0, "1 year, 2 months and 5 days");

  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-17", "2021-07-16", opt),
      0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "negative one day");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-23", "2021-07-16", opt),
      0, 0, 0, -7, 0, 0, 0, 0, 0, 0, "negative 7 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-08-16", "2021-07-16", opt),
      0, -1, 0, 0, 0, 0, 0, 0, 0, 0, "negative 1 month in same year");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-01-16", "2020-12-16", opt),
      0, -1, 0, 0, 0, 0, 0, 0, 0, 0, "negative 1 month in different year");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-02-05", "2021-01-05", opt),
      0, -1, 0, 0, 0, 0, 0, 0, 0, 0, "negative 1 month in same year");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-03-07", "2021-01-07", opt),
      0, -2, 0, 0, 0, 0, 0, 0, 0, 0, "negative 2 month in same year across Feb 28");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-08-17", "2021-07-16", opt),
      0, -1, 0, -1, 0, 0, 0, 0, 0, 0, "negative 1 month and 1 day in a month with 31 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-08-13", "2021-07-16", opt),
      0, 0, 0, -28, 0, 0, 0, 0, 0, 0, "negative 28 days roll across a month which has 31 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-09-16", "2021-07-16", opt),
      0, -2, 0, 0, 0, 0, 0, 0, 0, 0, "negative 2 months with both months which have 31 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2022-07-16", "2021-07-16", opt),
      -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "negative 1 year");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2031-07-16", "2021-07-16", opt),
      -10, 0, 0, 0, 0, 0, 0, 0, 0, 0, "negative 10 years");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2022-07-19", "2021-07-16", opt),
      -1, 0, 0, -3, 0, 0, 0, 0, 0, 0, "negative 1 year and 3 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2022-09-19", "2021-07-16", opt),
      -1, -2, 0, -3, 0, 0, 0, 0, 0, 0, "negative 1 year 2 months and 3 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2031-12-16", "2021-07-16", opt),
      -10, -5, 0, 0, 0, 0, 0, 0, 0, 0, "negative 10 years and 5 months");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "1997-12-16", opt),
      -23, -7, 0, 0, 0, 0, 0, 0, 0, 0, "negative 23 years and 7 months");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "1997-07-16", opt),
      -24, 0, 0, 0, 0, 0, 0, 0, 0, 0, "negative 24 years");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-15", "1997-07-16", opt),
      -23, -11, 0, -30, 0, 0, 0, 0, 0, 0, "negative 23 years, 11 months and 30 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-06-15", "1997-06-16", opt),
      -23, -11, 0, -29, 0, 0, 0, 0, 0, 0, "negative 23 years, 11 months and 29 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2020-03-16", "1960-02-16", opt),
      -60, -1, 0, 0, 0, 0, 0, 0, 0, 0, "negative 60 years, 1 month");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-03-15", "1960-02-16", opt),
      -61, 0, 0, -28, 0, 0, 0, 0, 0, 0, "negative 61 years, 28 days in non leap year");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2020-03-15", "1960-02-16", opt),
      -60, 0, 0, -28, 0, 0, 0, 0, 0, 0, "negative 60 years, 28 days in leap year");

  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "2021-03-30", opt),
      0, -3, 0, -17, 0, 0, 0, 0, 0, 0, "negative 3 months and 17 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "2020-03-30", opt),
      -1, -3, 0, -17, 0, 0, 0, 0, 0, 0, "negative 1 year, 3 months and 17 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "1960-03-30", opt),
      -61, -3, 0, -17, 0, 0, 0, 0, 0, 0, "negative 61 years, 3 months and 17 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "2019-12-30", opt),
      -1, -6, 0, -17, 0, 0, 0, 0, 0, 0, "negative 1 year, 6 months and 17 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "2020-12-30", opt),
      0, -6, 0, -17, 0, 0, 0, 0, 0, 0, "negative 6 months and 17 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "1997-12-30", opt),
      -23, -6, 0, -17, 0, 0, 0, 0, 0, 0, "negative 23 years, 6 months and 17 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-07-16", "0001-12-25", opt),
      -2019, -6, 0, -22, 0, 0, 0, 0, 0, 0, "negative 2019 years, 6 months and 22 days");
  TemporalHelpers.assertDuration(
      cal.dateUntil("2021-03-05", "2019-12-30", opt),
      -1, -2, 0, -6, 0, 0, 0, 0, 0, 0, "negative 1 year, 2 months and 6 days");
});

reportCompare(0, 0);