Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fewer CalendarDay/CalendarDateFromFields calls during PlainYearMonth add/subtract #2798

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4409,9 +4409,7 @@ export function AddDurationToOrSubtractDurationFromPlainYearMonth(operation, yea
let startDate = CalendarDateFromFields(calendar, fields, 'constrain');
if (sign < 0) {
const nextMonth = CalendarDateAdd(calendar, startDate, { months: 1 }, 'constrain');
const endOfMonth = BalanceISODate(nextMonth.year, nextMonth.month, nextMonth.day - 1);
fields.day = CalendarDay(calendar, endOfMonth);
startDate = CalendarDateFromFields(calendar, fields, 'constrain');
startDate = BalanceISODate(nextMonth.year, nextMonth.month, nextMonth.day - 1);
}
RejectDateRange(startDate.year, startDate.month, startDate.day);
const addedDate = CalendarDateAdd(calendar, startDate, { years, months, weeks, days }, overflow);
Expand Down
6 changes: 2 additions & 4 deletions spec/plainyearmonth.html
Original file line number Diff line number Diff line change
Expand Up @@ -759,10 +759,8 @@ <h1>
1. If _sign_ &lt; 0, then
1. Let _oneMonthDuration_ be ! CreateDateDurationRecord(0, 1, 0, 0).
1. Let _nextMonth_ be ? CalendarDateAdd(_calendar_, _intermediateDate_, _oneMonthDuration_, *"constrain"*).
1. Let _endOfMonth_ be BalanceISODate(_nextMonth_.[[Year]], _nextMonth_.[[Month]], _nextMonth_.[[Day]] - 1).
1. Assert: ISODateWithinLimits(_endOfMonth_.[[Year]], _endOfMonth_.[[Month]], _endOfMonth_.[[Day]]) is *true*.
1. Set _fields_.[[Day]] to CalendarDay(_calendar_, _endOfMonth_).
1. Let _date_ be ? CalendarDateFromFields(_calendar_, _fields_, *"constrain"*).
1. Let _date_ be BalanceISODate(_nextMonth_.[[Year]], _nextMonth_.[[Month]], _nextMonth_.[[Day]] - 1).
1. Assert: ISODateWithinLimits(_date_.[[Year]], _date_.[[Month]], _date_.[[Day]]) is *true*.
1. Else,
1. Let _date_ be _intermediateDate_.
1. Let _durationToAdd_ be ? CreateDateDurationRecord(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _days_).
Expand Down
Loading