valueOf

Returns the canonical month string (YYYY-MM). It defines how a Month coerces to a primitive, so template strings and string concatenation stay at month precision.

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

Month.from("2025-01").valueOf(); // "2025-01"
Month.from("2025-01-31").valueOf(); // "2025-01" — anchor never leaks

`${Month.from("2025-01")}`; // "2025-01"

API Reference

Signature

month.valueOf(): string;

Parameters

None.

Returns

Returns the canonical YYYY-MM string, regardless of any day anchor.

Agent Contract

FieldValue
Kindconversion
Canonical namevalueOf
Mutates receiverNo
Returnsstring
Precisionmonth (YYYY-MM)
Related methodstoString, toJSON

Agent Notes

  • valueOf always stays at month precision; use toString({ precision }) for explicit year or day output.
  • valueOf returns a string, not a number. Relational operators (monthA < monthB) work because the fixed-width YYYY-MM form orders lexicographically, but numeric coercion (+month, monthA - monthB) yields NaN by design. Use diff for signed month differences.
  • Comparison between Month values should use the comparison methods, not relational operators on the coerced string.