Methods
date.set()
Set year, month, and day coordinates simultaneously on a NepaliDate instance.
The set method updates the Bikram Sambat year, zero based month index, and day values of the current NepaliDate instance in a single atomic call. It validates the combined coordinates against the calendar map and recalculates the internal timestamp.
Import
import { NepaliDate } from "nepali-date-library";Signature
set(year: number, month: number, date: number): void;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
year | number | Yes | 4-digit Bikram Sambat year (1976 to 2100). |
month | number | Yes | 0-indexed month integer (0 for Baisakh to 11 for Chaitra). |
date | number | Yes | Day of the month (1 to 32). |
Return Value
- Type:
void - Mutates the current
NepaliDateinstance in place.
Exceptions
| Error Message | Trigger Condition |
|---|---|
Nepal year out of range | Thrown if year is earlier than 1976 BS or later than 2100 BS. |
Invalid nepali month must be between 1 - 12 | Thrown if month is outside 0 to 11. |
Invalid nepali date must be between 1 - <max> in <year> <month> | Thrown if date exceeds the days count for the target month and year. |
Example
import { NepaliDate } from "nepali-date-library";
const date = new NepaliDate();
// Mutate to 2081 Kartik 15 (month index 6)
date.set(2081, 6, 15);
console.log(date.format("YYYY-MM-DD")); // "2081-07-15"
console.log(date.getEnglishDate().toISOString()); // "2024-10-31T00:00:00.000Z"Related
date.setYear(): Mutate only the year component.date.setMonth(): Mutate only the month component.date.setDate(): Mutate only the day component.
Advertisement
date.getEnglishDate()
Retrieve the equivalent Gregorian date as a native JavaScript Date object.
date.setYear()
Set the Bikram Sambat year on a NepaliDate instance within the supported calendar range.