@@ -131,7 +131,19 @@ function calendarDateWeekOfYear(id, isoDate) {
131
131
return { week : woy , year : yow } ;
132
132
}
133
133
134
- function ISODateSurpasses ( sign , y1 , m1 , d1 , isoDate2 ) {
134
+ function ISODateSurpasses ( sign , baseDate , isoDate2 , years , months , weeks , days ) {
135
+ const yearMonth = ES . BalanceISOYearMonth ( baseDate . year + years , baseDate . month + months ) ;
136
+ let y1 = yearMonth . year ;
137
+ let m1 = yearMonth . month ;
138
+ let d1 = baseDate . day ;
139
+ if ( weeks !== 0 || days !== 0 ) {
140
+ const regulatedDate = ES . RegulateISODate ( y1 , m1 , d1 , 'constrain' ) ;
141
+ ( {
142
+ year : y1 ,
143
+ month : m1 ,
144
+ day : d1
145
+ } = ES . BalanceISODate ( regulatedDate . year , regulatedDate . month , regulatedDate . day + 7 * weeks + days ) ) ;
146
+ }
135
147
if ( y1 !== isoDate2 . year ) {
136
148
if ( sign * ( y1 - isoDate2 . year ) > 0 ) return true ;
137
149
} else if ( m1 !== isoDate2 . month ) {
@@ -192,25 +204,22 @@ impl['iso8601'] = {
192
204
193
205
let years = 0 ;
194
206
let months = 0 ;
195
- let intermediate ;
196
207
if ( largestUnit === 'year' || largestUnit === 'month' ) {
197
208
// We can skip right to the neighbourhood of the correct number of years,
198
209
// it'll be at least one less than two.year - one.year (unless it's zero)
199
210
let candidateYears = two . year - one . year ;
200
211
if ( candidateYears !== 0 ) candidateYears -= sign ;
201
212
// loops at most twice
202
- while ( ! ISODateSurpasses ( sign , one . year + candidateYears , one . month , one . day , two ) ) {
213
+ while ( ! ISODateSurpasses ( sign , one , two , candidateYears , 0 , 0 , 0 ) ) {
203
214
years = candidateYears ;
204
215
candidateYears += sign ;
205
216
}
206
217
207
218
let candidateMonths = sign ;
208
- intermediate = ES . BalanceISOYearMonth ( one . year + years , one . month + candidateMonths ) ;
209
219
// loops at most 12 times
210
- while ( ! ISODateSurpasses ( sign , intermediate . year , intermediate . month , one . day , two ) ) {
220
+ while ( ! ISODateSurpasses ( sign , one , two , years , candidateMonths , 0 , 0 ) ) {
211
221
months = candidateMonths ;
212
222
candidateMonths += sign ;
213
- intermediate = ES . BalanceISOYearMonth ( intermediate . year , intermediate . month + sign ) ;
214
223
}
215
224
216
225
if ( largestUnit === 'month' ) {
@@ -219,7 +228,7 @@ impl['iso8601'] = {
219
228
}
220
229
}
221
230
222
- intermediate = ES . BalanceISOYearMonth ( one . year + years , one . month + months ) ;
231
+ const intermediate = ES . BalanceISOYearMonth ( one . year + years , one . month + months ) ;
223
232
const constrained = ES . ConstrainISODate ( intermediate . year , intermediate . month , one . day ) ;
224
233
225
234
let weeks = 0 ;
0 commit comments