Skip to content

getWeeksInMonth

getWeeksInMonth(value: string, locale: string): number
import { getWeeksInMonth } from "@northguild/gmt/plain/calculate";

Return the number of calendar-grid rows (4, 5, or 6) value’s month

  • spans, using locale’s first day of week.
  • The count depends on which day the week starts — the same month can span 4, 5, or 6 rows depending on locale (e.g. February 2026 is 4 rows starting Sunday but 5 rows starting Monday).
  • Sized the same way @internationalized/date’s getWeeksInMonth sizes a datepicker’s calendar grid.
  • Resolves the locale’s first day of week via Intl.Locale.prototype.weekInfo.
  • Returns null if value or locale is invalid.
Parameter Type Description
value string ISO PlainDate string
locale string BCP 47 locale tag (e.g. “en-US”, “fr-FR”)

number of week-rows the month spans (4-6), or null on invalid input

getWeeksInMonth("2024-02-15", "en-US") // 5
getWeeksInMonth("2026-02-15", "en-US") // 4
getWeeksInMonth("2026-02-15", "en-GB") // 5
getWeeksInMonth("invalid", "en-US") // null

plain/calculate/getWeeksInMonth.ts