Methods
date.setDate()
Set the day of the month on a NepaliDate instance and recalculate its timestamp.
The setDate method updates the day of the month for the current NepaliDate instance and recalculates its underlying Gregorian timestamp. It validates the new day against the maximum number of days available in the active month.
Import
import { NepaliDate } from "nepali-date-library";Signature
setDate(day: number): void;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
day | number | Yes | Day of the month (1 to 32, validated against current month's length). |
Return Value
- Type:
void - Mutates the current
NepaliDateinstance in place.
Exceptions
| Error Message | Trigger Condition |
|---|---|
Invalid nepali date must be between 1 - <max> in <year> <month> | Thrown if day is less than 1 or greater than the maximum days in the current month for this year. |
Example
import { NepaliDate } from "nepali-date-library";
const date = new NepaliDate("2081-01-01");
date.setDate(25);
console.log(date.format("YYYY-MM-DD")); // "2081-01-25"Related
date.getDate(): Retrieve the day of the month.date.daysInMonth(): Query the maximum allowed day count for this month.
Advertisement
date.setMonth()
Set the Bikram Sambat month index on a NepaliDate instance with automatic day clamping.
date.parse()
Parse a formatted Bikram Sambat date string and update the current date instance in place.