from

Creates a Month value from a canonical month string, a year/month pair, a month object, or another Month value.

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

Month.from("2025-01").toString(); // "2025-01"
Month.from(2025, 1).toString(); // "2025-01"
Month.from({ year: 2025, month: 12 }).toString(); // "2025-12"
Month.from(Month.from("2025-07")).toString(); // "2025-07"

// Surrounding whitespace is accepted and output is canonical.
Month.from(" 2025-01 ").toString(); // "2025-01"

// Expanded signed years are supported when arithmetic crosses normal YYYY range.
Month.from("-0001-12").add(1).toString(); // "0000-01"
Month.from("+10000-01").sub(1).toString(); // "9999-12"

API Reference

Signatures

Month.from(value: MonthValue): MonthInstance;
Month.from(year: number, month: number): MonthInstance;
Month.fromIndex(index: number): MonthInstance;

Parameters

ParameterTypeRequiredNotes
valueMonthValueYesstring, MonthInstance, or { year, month }.
yearnumberYesSafe integer year.
monthnumberYesSafe integer from 1 through 12.
indexnumberYesSafe integer serial month index where 0000-01 is 0.

Returns

Returns an immutable MonthInstance.

Throws

  • Throws for invalid month strings.
  • Throws when year, month, or index is not a safe integer.
  • Throws when month is outside 1..12.

Agent Contract

FieldValue
Kindstatic factory
Canonical namefrom
AliasesNone
Mutates receiverNo
ReturnsMonthInstance
Related methodsfromIndex, isMonth, toObject, toString

Agent Notes

  • Generate Month.from(...), not new Month(...) or Month(...).
  • Import with import { Month } from "@teakit/month"; default imports are unsupported.
  • Prefer canonical YYYY-MM strings for normal years.
  • Do not use JavaScript Date parsing for month-only values.