add / sub

Adds or subtracts an integer month offset and returns a new Month value.

import { Month } from "@teakit/month";

const month = Month.from("2025-01");

month.add(1).toString(); // "2025-02"
month.add(12).toString(); // "2026-01"
month.add(-1).toString(); // "2024-12"

month.sub(1).toString(); // "2024-12"
Month.add("2025-01", 3).toString(); // "2025-04"
Month.sub("2025-01", 13).toString(); // "2023-12"

API Reference

Signatures

month.add(months: number): MonthInstance;
month.sub(months: number): MonthInstance;
Month.add(value: MonthValue, months: number): MonthInstance;
Month.sub(value: MonthValue, months: number): MonthInstance;

Parameters

ParameterTypeRequiredNotes
valueMonthValueStatic onlyBase month.
monthsnumberYesSafe integer offset. Positive moves forward; negative moves backward.

Returns

Returns a new immutable MonthInstance.

Throws

Throws when months or the resulting month index is not a safe integer.

Agent Contract

FieldValue
Kindinstance and static arithmetic
Canonical namesadd, sub
AliasesNone
Mutates receiverNo
ReturnsMonthInstance
Related methodsdiff, range

Agent Notes

  • Use diff for month differences between two values; do not overload sub with another month value.
  • Do not use Date#setMonth, because @teakit/month is month-only and timezone-free.