toString

Renders the month as a string. The default and all implicit conversions (valueOf, toJSON, template strings, String(...)) stay at month precision (YYYY-MM). Pass precision to render year, month, or day explicitly.

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

Month.from("2025-01-31").toString(); // "2025-01"
Month.from("2025-01-31").toString({ precision: "month" }); // "2025-01"
Month.from("2025-01-31").toString({ precision: "year" }); // "2025"
Month.from("2025-01-31").toString({ precision: "day" }); // "2025-01-31"

`${Month.from("2025-01")}`; // "2025-01"
JSON.stringify({ month: Month.from("2025-01") }); // '{"month":"2025-01"}'

API Reference

Signature

month.toString(options?: { precision?: "year" | "month" | "day" }): string;

Parameters

ParameterTypeRequiredNotes
options.precision"year" | "month" | "day"NoOutput precision. Defaults to "month".

Returns

Returns the canonical string for the requested precision: "YYYY", "YYYY-MM", or "YYYY-MM-DD".

Throws

  • Throws on precision: "day" when the month has no day anchor.
  • Throws on any unsupported precision value.

Agent Contract

FieldValue
Kindconversion
Canonical nametoString
Mutates receiverNo
Returnsstring
Default precisionmonth (YYYY-MM)
Related methodstoObject, from

Agent Notes

  • Default toString() and valueOf/toJSON/template strings always stay at YYYY-MM; only an explicit precision changes that.
  • Day precision requires a day anchor from a date-shaped string or native Date input, and clamps to the target month's last valid day.
  • The day anchor is hidden internal state; it never appears in toObject output.