Nepali DateNepali DateBikram Sambat Date Engine
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

ParameterTypeRequiredDescription
yearnumberYes4-digit Bikram Sambat year (1976 to 2100).
monthnumberYes0-indexed month integer (0 for Baisakh to 11 for Chaitra).
datenumberYesDay of the month (1 to 32).

Return Value

  • Type: void
  • Mutates the current NepaliDate instance in place.

Exceptions

Error MessageTrigger Condition
Nepal year out of rangeThrown if year is earlier than 1976 BS or later than 2100 BS.
Invalid nepali month must be between 1 - 12Thrown 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"

Advertisement

On this page