Import the plugin to hold a calendar month without pretending it is the first of the month. Loading it also adds .yearMonth and as('yearMonth') to calendar dates and zoned datetimes.
year-month.js
import { date, today } from 'native-dates';import { monthYear, yearMonth } from '@native-dates/plugins/year-month';const billing = yearMonth('2026-11');const expiry = monthYear('11/28');billing.plus(2, 'months').toString(); // '2027-01'billing.contains(date('2026-11-16')); // trueexpiry.isFuture(); // truetoday().as('yearMonth').on(15); // 15th of the current month
Reads an ISO year-month string, two whole numbers, a fields object, or any date or timestamp with its day dropped. With loose mode from the loose plugin, it also reads English month names paired with a four-digit year and returns null when unreadable.
Parameters
inputYearMonthInput | numberrequired
ISO year-month string, fields object, existing date or timestamp, or the 4-digit year.
optionsZone | ReadOptions | number
Time zone or options object when reading a timestamp or loose string, or 1-indexed month from 1 to 12.
2 options
zoneZone
Time zone used to determine the calendar month of an instant string, DateTime, or Date.
loosebooleandefault false
Read named months like 'Nov 2026' and return null instead of throwing when unreadable.
Returns
YearMonth
An immutable YearMonth, or null when loose mode cannot read input.
Reads month-first strings and number pairs in the order printed on payment cards. Two-digit years are added to YearMonth.century, defaulting to 2000, while ISO year-month strings still read year-first.
Parameters
inputYearMonthInput | string | numberrequired
Card-style 'MM/YY' or 'MM/YYYY' string, 1-indexed month, or any YearMonthInput.
optionsZone | ReadOptions | number
Two- or four-digit year when passing two numbers, or a zone or options object.
Returns
YearMonth
An immutable YearMonth, or null when loose mode cannot read input.
Adding days, weeks, or hours to a YearMonth throws a range error instead of silently dropping remainder days. Call on() first when you want a specific day of the month.
Returns the CalendarDate for that 1-indexed day of the month. Passing 31 clamps to the last day of shorter months, while numbers below 1 or above 31 throw an error.
contains() checks whether a date or timestamp falls within this calendar month. Past and future checks compare against the full month in the target zone, so the current month is neither past nor future.
Parameters
dayCalendarDateInput
Date or timestamp tested by contains().
zoneZone
Time zone used by isPast() and isFuture() to determine the current month.
ym.until(other, unit?): Duration | numberym.since(other, unit?): Duration | number
Measures the span between two year-month values. Without a unit, it returns a Duration of years and months, and passing a unit returns the signed numeric total.
Parameters
otherYearMonthInputrequired
Target or starting month.
unitUnit
Unit name to return a numeric count instead of a Duration.
Returns
Duration | number
Span as a Duration, or a signed number when unit is given.
Formats the year and month through Intl, printing only year, month, and era parts. Accepts any preset name, an options object, custom entries on YearMonth.presets, or token patterns when the tokens plugin is loaded.
Parameters
specFormatSpecdefault 'medium'
Preset name such as 'short' or 'long', Intl.DateTimeFormatOptions, or token pattern.
localestring
BCP 47 locale tag overriding the configured default for this call.