Nepali DateNepali DateBikram Sambat Date Engine
Static Methods

NepaliDate.isValid()

Static validation function to verify whether a given year, month, and day combination forms a valid Bikram Sambat date.

The static isValid method verifies whether a specified Bikram Sambat year, month index, and day number represent a real calendar date. It consults verified historical data tables to confirm that the year falls within the supported range of 1976 through 2100 BS and that the day number does not exceed the actual number of days in that specific month.


Import

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

Signature

static isValid(year: number, month: number, day: number): boolean;

Parameters

ParameterTypeRequiredDescription
yearnumberYesBikram Sambat year (e.g. 2081). Supported range: 1976 to 2100.
monthnumberYesZero-indexed month (0-11, where 0 is Baisakh and 11 is Chaitra).
daynumberYesDay of the month (1-32).

Return Value

  • Type: boolean
  • Returns true if the year is within supported range, month is between 0 and 11, and day does not exceed the exact number of days in that month; otherwise returns false.

Examples

Pre-validating User Input

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

// 2081 Baisakh 31 is valid (Baisakh has 31 days)
console.log(NepaliDate.isValid(2081, 0, 31)); // true

// 2081 Baisakh 32 does not exist
console.log(NepaliDate.isValid(2081, 0, 32)); // false

// Month index must be 0-11
console.log(NepaliDate.isValid(2081, 12, 1)); // false

Form Input Validation Guard

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

function createNepaliEvent(y: number, m: number, d: number) {
  if (!NepaliDate.isValid(y, m, d)) {
    throw new Error(`Invalid Bikram Sambat date: ${y}-${m + 1}-${d}`);
  }
  return new NepaliDate(y, m, d);
}

Advertisement

On this page