temporal-fns
API reference

getWeeksInMonth

API index · Input types and conventions · Installation

getWeeksInMonth(value, options?) → number

Count the week rows that intersect the represented month. Accepts calendar values and PlainYearMonth with optional weekStartsOn. This is a grid row count, not a count of full weeks; it also works for partial months at Temporal's range limits.

import { getWeeksInMonth } from '@frantss/temporal-fns';

getWeeksInMonth(Temporal.PlainYearMonth.from('2026-02')); // => 4
getWeeksInMonth(Temporal.PlainYearMonth.from('2026-05')); // => 6
getWeeksInMonth(Temporal.PlainYearMonth.from('2026-05'), { weekStartsOn: 1 }); // => 5
getWeeksInMonth(Temporal.PlainYearMonth.from('-271821-04')); // => 5

Related: getWeekOfMonth, eachWeekOfInterval, startOfMonth.

Behaviors: CAL-009: Month grid size needs a year and month but does not need a day; CAL-013: Every week-grid query validates its weekday boundary; CAL-014: Month grids at the limits do not invent a required reference day.