Skip to content

Commit 3d72048

Browse files
Ms2gerptomato
authored andcommitted
Handle opposite date/time signs in DifferenceISODateTime.
This ensures cases such as months=1, hours=-1 are balanced correctly. Fixes #1415.
1 parent ef91b3d commit 3d72048

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lib/ecmascript.mjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3290,7 +3290,35 @@ export const ES = ObjectAssign({}, ES2020, {
32903290
µs2,
32913291
ns2
32923292
);
3293+
3294+
const timeSign = ES.DurationSign(
3295+
0,
3296+
0,
3297+
0,
3298+
deltaDays,
3299+
hours,
3300+
minutes,
3301+
seconds,
3302+
milliseconds,
3303+
microseconds,
3304+
nanoseconds
3305+
);
32933306
({ year: y1, month: mon1, day: d1 } = ES.BalanceISODate(y1, mon1, d1 + deltaDays));
3307+
const dateSign = ES.CompareISODate(y2, mon2, d2, y1, mon1, d1);
3308+
if (dateSign === -timeSign) {
3309+
({ year: y1, month: mon1, day: d1 } = ES.BalanceISODate(y1, mon1, d1 - timeSign));
3310+
({ hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = ES.BalanceDuration(
3311+
-timeSign,
3312+
hours,
3313+
minutes,
3314+
seconds,
3315+
milliseconds,
3316+
microseconds,
3317+
nanoseconds,
3318+
largestUnit
3319+
));
3320+
}
3321+
32943322
const date1 = ES.CreateTemporalDate(y1, mon1, d1, calendar);
32953323
const date2 = ES.CreateTemporalDate(y2, mon2, d2, calendar);
32963324
const dateLargestUnit = ES.LargerOfTwoTemporalDurationUnits('days', largestUnit);

0 commit comments

Comments
 (0)