subtractYearMonth
Signature
Section titled “Signature”subtractYearMonth(value: string, units: { years?: number; months?: number; }): stringReturn a year-month string moved backward by units.
- The same rules as
addYearMonth: years and months only ({ days: 1 }and{ weeks: 1 }return""), nothing to clamp, and""for invalid input. - The amounts are not negated here, so the sign rules (mixed signs,
-0) are Temporal’s. - The subtraction starts from day 1 of the month, as the specification’s AddDurationToYearMonth does with operation
subtract(it negates the duration, then sets [[Day]] to 1), so+275760-09minus a month is+275760-08and-271821-05minus a month is""(day 1 of-271821-04is out of range).
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 subtract. |
months? | number | no months; at least one of years and months must be given. | Whole months to subtract. |
Returns
Section titled “Returns”the year-month string after the subtraction, or "" on invalid input
Examples
Section titled “Examples”import { subtractYearMonth } from "@northguild/gmt/plain/calculate";
subtractYearMonth("2026-10", { months: 10 }) // "2025-12"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.