Skip to content

@jsvision/ui / addMonths

Function: addMonths()

addMonths(date, n): CalendarDate

Defined in: ui/src/date/calendar-date.ts:87

Add n months (may be negative); the day is clamped to the target month's length, so the result is always a valid date.

Parameters

date

CalendarDate

The civil date.

n

number

Months to add (negative to subtract).

Returns

CalendarDate

A fresh, valid CalendarDate.

Example

ts
addMonths({ year: 2026, month: 1, day: 31 }, 1);  // { year: 2026, month: 2, day: 28 } (day clamped)
addMonths({ year: 2026, month: 1, day: 15 }, -2); // { year: 2025, month: 11, day: 15 }