getWeekArray

Commons
stable

Builds a 2-D array of Date objects representing the calendar grid for the month containing the given date. Each inner array is one week (7 days). Padding days from adjacent months fill the first and last partial weeks.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

date
required
Date
Any date within the target month. Only the month and year are used.
locale
required
string
BCP 47 locale tag used to look up the locale-specific first day of the week when firstDayOfWeek is omitted (e.g. "en-US" → Sunday, "fr-FR" → Monday).
firstDayOfWeek
number
Explicit override for the first day of the week (0 = Sunday, 1 = Monday, …). When provided it takes priority over the locale lookup.

API

Return value

The value returned by this util.

A 2-D array of Date objects. Length is 4–6 outer rows, each inner row has exactly 7 elements.

Usage

Examples

Ready-to-paste usage snippets.

Build a January 2024 calendar grid

typescript