diff

Calculates left - right in whole calendar months.

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

Month.from("2025-03").diff("2025-01"); // 2
Month.from("2025-01").diff("2025-03"); // -2

Month.diff("2025-03", "2025-01"); // 2
Month.diff("2024-12", "2025-01"); // -1

API Reference

Signatures

month.diff(other: MonthValue): number;
Month.diff(left: MonthValue, right: MonthValue): number;

Parameters

ParameterTypeRequiredNotes
otherMonthValueInstance onlyMonth subtracted from the receiver.
leftMonthValueStatic onlyLeft-hand month.
rightMonthValueStatic onlyRight-hand month.

Returns

Returns a signed integer month count.

Agent Contract

FieldValue
Kinddifference
Canonical namediff
Directionleft - right
Mutates receiverNo
Returnsnumber
Related methodsadd/sub

Agent Notes

  • For "months from start to end", generate Month.from(end).diff(start).
  • For offset arithmetic, use add or sub instead of calculating an index manually.