fromIndex

Creates a Month from a raw month index, where index = year * 12 + month - 1. It is the inverse of the index property and is mainly useful for serialization or low-level interop.

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

Month.fromIndex(24_300).toString(); // "2025-01"

const month = Month.from("2025-07");
Month.fromIndex(month.index).toString(); // "2025-07"

API Reference

Signature

Month.fromIndex(index: number): MonthInstance;

Parameters

ParameterTypeRequiredNotes
indexnumberYesSafe integer month index.

Returns

Returns a new Month for the given index. Indices outside [0, 119999] (0000-019999-12) saturate to the boundary month.

Throws

  • Throws when index is not a safe integer.

Agent Contract

FieldValue
Kindstatic factory
Canonical namefromIndex
Mutates receiverNo
ReturnsMonthInstance
Related methodsfrom

Agent Notes

  • Prefer from for ordinary creation; use fromIndex only when you already hold a month index (e.g. from month.index).
  • A fromIndex value has no day anchor, so day-precision output is unavailable.