diffYearMonth
Signature
Section titled “Signature”diffYearMonth(a: string, b: string, unit: "years" | "months" | "year" | "month"): number | nullReturn the whole years or months from year-month a to year-month b.
unitis"years","year","months"or"month"; any other unit returnsnull(Temporal’s DifferenceTemporalPlainYearMonth allows years and months only).- Direction is from
atob: positive whenbis later, negative when earlier. - The result is truncated toward zero, so
2025-11to2027-10is 1 year; never-0. - The lowest year-month (
-271821-04) can only be compared with itself (0); against any other year-month, day 1 is out of range and the result isnull. - In
years, a pair whose next whole year passes+275760-09or-271821-04returnsnull(Temporal’s ComputeNudgeWindow computes the end bound one year further; the call throws). - Returns
nullfor a string that is not a year-month.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
a | string | year-month string for the start |
b | string | year-month string for the end |
unit | "years" | "months" | "year" | "month" | unit to measure in |
Returns
Section titled “Returns”the difference in unit, or null on invalid input
Examples
Section titled “Examples”import { diffYearMonth } from "@northguild/gmt/plain/calculate";
diffYearMonth("2025-11", "2026-10", "months") // 11Source
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.