Nepali DateNepali DateBikram Sambat Date Engine
Methods

date.getWeeksInMonth()

Calculate the number of calendar week rows required to render the current month in a grid.

The getWeeksInMonth method computes the total number of seven day week rows required to display the entire month in a standard calendar grid. Depending on which weekday the month starts on and how many days it contains, the returned count is usually five or six rows.


Import

import { NepaliDate } from "nepali-date-library";

Signature

getWeeksInMonth(): number;

Parameters

This method does not take any parameters.


Return Value

  • Type: number
  • The number of calendar week rows needed (typically 5 or 6).

Formula

The calculation evaluates the weekday offset of the 1st of the month added to the month's total days, divided by 7:

Math.ceil((firstDayOfWeek + totalDays) / 7)

Examples

Sizing UI Calendar Views

import { NepaliDate } from "nepali-date-library";

const date = new NepaliDate("2081-01-15");
const rowCount = date.getWeeksInMonth();

console.log(`Calendar requires ${rowCount} week rows.`);

Advertisement

On this page