addYearMonth
Signature
Section titled “Signature”addYearMonth(value: string, units: { years?: number; months?: number; }): stringReturn a year-month string moved forward by units.
- Takes years and months only: a year-month has no day, so
{ days: 1 },{ weeks: 1 }and the time units return"". An owndays,weeksor time key returns""whatever its value ({ months: 1, days: 0 }): the misspelt-key guard. An inherited zero is no amount. - The result is a year-month, so no day is clamped:
2024-02plus a year is2025-02. - A negative amount moves backward; mixed signs, fractions, a misspelt key, a non-number and no unit at all return
"". - The lowest year-month (
-271821-04) cannot be moved, even by zero, and a result beyond+275760-09returns"". - Accepts
YYYY-MMand the formsisValidYearMonthaccepts; the result is alwaysYYYY-MM(±YYYYYY-MMoutside 0000-9999).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | year-month string |
Options
Section titled “Options”units
the amounts to move the year-month by
| Option | Type | Default | Description |
|---|---|---|---|
years? | number | no years; at least one of years and months must be given. | Whole years to add. |
months? | number | no months; at least one of years and months must be given. | Whole months to add. |
Returns
Section titled “Returns”the year-month string after the addition, or "" on invalid input
Examples
Section titled “Examples”import { addYearMonth } from "@northguild/gmt/plain/calculate";
addYearMonth("2026-10", { months: 1 }) // "2026-11"Source
Section titled “Source”Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else:© 2026 NorthGuild, all rights reserved.