UNPKG

@northguild/gmt

Version:

Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.

21 lines (20 loc) • 971 B
// src/internal/monthGridWeekRow.ts /** * Return the 1-based calendar-grid week row that `dayInMonth` falls on for * `firstOfMonth`'s month, given `firstDay` (locale first day of week, * 1 = Monday .. 7 = Sunday). * * Shared by `getWeekOfMonth` (row for the date itself) and * `getWeeksInMonth` (row for the month's last day, i.e. the row count). * Week 1 is the row containing the 1st of the month, even when that row * is a partial week: a month grid draws every day of the month, so its * first row always holds the 1st. GMT's own rule; CLDR's `minDays` plays no part. * * Only the weekday of the 1st is read, so callers may pass `{ dayOfWeek }` without building a * date that could lie before the representable range (April 1 of -271821). */ function monthGridWeekRow(firstOfMonth, firstDay, dayInMonth) { const leadingOffset = (firstOfMonth.dayOfWeek - firstDay + 7) % 7; return Math.floor((leadingOffset + dayInMonth - 1) / 7) + 1; } export { monthGridWeekRow };