Static Methods
NepaliDate.getDayName()
Static utility to retrieve the localized English or Nepali name for any day of the week index.
The getDayName static method converts a numeric weekday index from 0 for Sunday through 6 for Saturday into its localized name. It supports both English and Nepali Devanagari script output, allowing flexible localization across international and local application interfaces.
Import
import { NepaliDate } from "nepali-date-library";Signature
static getDayName(day: number, short?: boolean, nepali?: boolean): string;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
day | number | Yes | - | Day of week index (0-6, where 0 is Sunday and 6 is Saturday). |
short | boolean | No | false | When true, returns the abbreviated 3-letter or short weekday name. |
nepali | boolean | No | false | When true, returns the weekday name in Devanagari script. |
Return Value
- Type:
string - Localized day of week name string.
Exceptions
Throws an Error if day is less than 0 or greater than 6:
"Invalid day index, must be between 0-6"Output Reference Matrix
| Day Index | Default (short: false, nepali: false) | Short English (short: true, nepali: false) | Nepali Full (short: false, nepali: true) | Nepali Short (short: true, nepali: true) |
|---|---|---|---|---|
0 | "Sunday" | "Sun" | "आइतबार" | "आइत" |
1 | "Monday" | "Mon" | "सोमबार" | "सोम" |
2 | "Tuesday" | "Tue" | "मंगलबार" | "मंगल" |
3 | "Wednesday" | "Wed" | "बुधबार" | "बुध" |
4 | "Thursday" | "Thu" | "बिहिबार" | "बिहि" |
5 | "Friday" | "Fri" | "शुक्रबार" | "शुक्र" |
6 | "Saturday" | "Sat" | "शनिबार" | "शनि" |
Examples
Generating Weekday Labels for UI
import { NepaliDate } from "nepali-date-library";
// Default English
console.log(NepaliDate.getDayName(0)); // "Sunday"
// English Short
console.log(NepaliDate.getDayName(0, true)); // "Sun"
// Nepali Devanagari Full
console.log(NepaliDate.getDayName(0, false, true)); // "आइतबार"
// Nepali Devanagari Short
console.log(NepaliDate.getDayName(0, true, true)); // "आइत"Related
NepaliDate.getMonthName(): Localized month names.WEEK_EN: English week array constant.WEEK_NP: Nepali week array constant.
Advertisement
NepaliDate.getMonthName()
Static utility to retrieve the localized English or Nepali month name for any month index.
NepaliDate.getCalendarDays()
Static utility to generate a complete forty two cell calendar grid matrix for any month and year.