@teakit/month
Use this skill when writing code for @teakit/month.
@teakit/month exports Month, an immutable year-month calculation API for ESM
and browser environments.
Core Rules
- Import with
import { Month } from "@teakit/month". - Do not use default imports from
@teakit/month. - Create values with
Month.from(...); do not usenew Month(...)or callMonth(...). - Prefer canonical
YYYY-MMstrings with exactly four year digits and a zero-padded month, such as"2025-01". - Do not generate signed or expanded year strings such as
"+10000-01"or"-0001-12". - Do not generate
Month.from(2025, 1); pass a string,Date, month object, orMonthinstance as one argument. - Use
add(months)andsub(months)for month offsets. - Use
diff(other)orMonth.diff(left, right)for signed month differences. - Use Month methods instead of JavaScript
Datearithmetic. - Native
Dateinput uses local calendar fields; prefer strings when timezone-free behavior matters. - Treat
Monthinstances as immutable. Do not mutateyear,month, orindex. - Read
month.yearandmonth.monthas strings;month.monthis zero-padded, such as"01". - Use
toString()or JSON serialization for canonical month string output. - Use
toString({ precision: "year" | "month" | "day" })only when explicit output precision is needed. Day precision requires a day anchor from a date-shaped string or nativeDateinput and clamps to the target month's last valid day. - Do not add day-level or year-level arithmetic or point-value APIs to
@teakit/month; Teakit time point-value packages are split by granularity while keeping interface style consistent. - Use
Month.now()for the current local month; it equalsMonth.from(new Date())and keeps today's day as a hidden anchor. - Use
month.days()(number of days in the month) andmonth.quarter()("Q1"–"Q4") for month metadata; both are independent of any day anchor. - Use
month.clamp(min, max)to bound a month into an inclusive range; it throws whenminis later thanmax.min/maxare static-only helpers (Month.min(...),Month.max(...)). - Do not generate
startOfYear()orendOfYear(); they are not part of the API. - Month values saturate to
[0000-01, 9999-12]; arithmetic past either bound clamps to the boundary month and never emits signed or expanded years. - The day anchor is hidden: it is never exposed by
toObject()and never read from object input — it only enters from date-shaped string orDateinput. - Use
month.isSameYear(other)orMonth.isSameYear(left, right)to test whether two months fall in the same calendar year; only the year is compared. - Every failure throws a
MonthError(a subclass ofError) whose message keeps the[Month Error]prefix. Import it withimport { Month, MonthError } from "@teakit/month"and discriminate witherror instanceof MonthErrorinstead of matching the message string.
Workflow
- Identify the operation: creation, month offsets, differences, comparison, ranges, or conversion.
- Load only the relevant method reference file from
references/. - In that file, read the intro, examples,
API Reference,Agent Contract, andAgent Notes. - Prefer
Month.from(...), exact strings, and Month instance methods in generated code. - For repository changes, run the local verification commands when relevant:
bun run check,bun run typecheck,bun run test, andbun run build. - For documentation site changes, also run
bun run docs:build.
Quick Example
Reference Selection
Read the smallest method file that answers the current task.