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
| Parameter | Type | Required | Description |
|---|---|---|---|
year | number | Yes | Bikram Sambat year (e.g. 2081). Supported range: 1976 to 2100. |
month | number | Yes | Zero-indexed month (0-11, where 0 is Baisakh and 11 is Chaitra). |
day | number | Yes | Day of the month (1-32). |
Return Value
- Type:
boolean - Returns
trueif the year is within supported range, month is between0and11, and day does not exceed the exact number of days in that month; otherwise returnsfalse.
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)); // falseForm 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);
}Related
date.isValid(): Instance method equivalent.date.daysInMonth(): Query total days in a month.
Advertisement
date.clone()
Create an independent deep clone of an existing NepaliDate instance.
NepaliDate.minimum()
Static method returning the minimum supported date boundary for the NepaliDate calendar engine.