@teakit/month

@teakit/month is a TypeScript year-month calculation package for ESM and browser environments.

Guide

Use this page as the short human entrypoint. Keep detailed API behavior in the method reference pages.

NeedRead
Install and try the packageInstallation & Usage
Find a method by taskReference Map
Compact rules for AI agentsLLMs
Skill instructions for agent runtimesSkill Instructions

Installation & Usage

npm
yarn
pnpm
bun
deno
npm install @teakit/month
import { Month } from "@teakit/month";

const current = Month.from("2025-01");
const nextQuarter = current.add(3);

current.year; // "2025"
current.month; // "01"
Month.from("2025-01-15").toString(); // "2025-01"
Month.from(new Date(2025, 0, 15)).toString(); // "2025-01"
Month.from("2025-01-31").add(1).toString({ precision: "day" }); // "2025-02-28"
Month.from("2025-07").toString({ precision: "year" }); // "2025"
nextQuarter.toString(); // "2025-04"
Month.range("2025-01", "2025-03").map(String); // ["2025-01", "2025-02", "2025-03"]

Always create values with Month.from(...). Use diff for month differences and add or sub for month offsets.

Package Contract

  • Import Month from @teakit/month.
  • Create values with Month.from(...); do not use new Month(...) or call Month(...).
  • Use canonical YYYY-MM strings with exactly four year digits and a zero-padded month.
  • Accept date-like strings and native Date objects at the input boundary when callers already have them; Date objects use local calendar fields, so prefer strings when timezone-free behavior matters.
  • Use toString({ precision: "year" | "month" | "day" }) only when explicit output precision is needed; default toString() remains YYYY-MM.
  • Read month.year and month.month as strings; month.month is zero-padded.
  • Treat Month instances as immutable.
  • Use Month methods instead of JavaScript date arithmetic.
  • The package is browser-safe ESM and has no Node runtime imports.

Reference Map

TaskMethods
Constructionfrom, fromIndex, now, isMonth
Month offsetsadd, sub
Differencesdiff
Rangesrange
Comparisoncmp, eq, ne, gt, ge, lt, le
Static utilitiesmin, max
Metadata & boundsdays, quarter, clamp
ConversiontoString, toJSON, valueOf, toObject

LLMs

AI agents should start with LLMs, then open only the relevant method reference file. Reference pages keep human usage first and AI-specific contracts near the end.