Skip to content

TypeScript and JavaScript

Two npm packages, released together with the same version:

  • nepdate-core: dates, conversion, arithmetic, formatting and parsing. ESM only, types included, zero dependencies, no event data.
  • nepdate-patro: tithi, public holidays and events from BS 2077-01-01 to 2084-08-20. It needs nepdate-core as a peer dependency.

For a BS date picker in the browser, see Date picker: a third package, nepdate-datepicker, built on the core.

Pure TypeScript, no WASM and no time zone guessing. Node 22.12.0 and later, Deno, Bun and current browsers.

Terminal window
npm install nepdate-core@beta
import { NepaliDate } from "nepdate-core";
const republicDay = NepaliDate.of(2081, 2, 15);
console.log(republicDay.toGregorian()); // { year: 2024, month: 5, day: 28 }
console.log(republicDay.toJSON()); // "2081-02-15"
console.log(republicDay.long({ weekday: true })); // "Tuesday, Jestha 15, 2081"

toJSON() is the interchange form, "YYYY-MM-DD". toString() is the display form, "YYYY/MM/DD". Months are 1-based everywhere, unlike JavaScript’s Date.

today(timeZone = "Asia/Kathmandu") reads the clock through Intl.DateTimeFormat with that zone, so the machine’s own zone never changes the answer.

GregorianDate is structural: a Temporal.PlainDate satisfies it, so no Temporal dependency is needed. fromJSDate and toJSDate take an explicit zone because a Date holds an instant, not a calendar day.

import { NepaliDate } from "nepdate-core";
if (globalThis.Temporal !== undefined) {
const date = NepaliDate.fromGregorian(Temporal.PlainDate.from("2024-07-30"));
console.log(date.toJSON()); // "2081-04-15"
console.log(Temporal.PlainDate.from(date.toGregorian()).toString()); // "2024-07-30"
}
Terminal window
npm install nepdate-core@beta nepdate-patro@beta
import { NepaliDate } from "nepdate-core";
import { info } from "nepdate-patro";
const day = info(NepaliDate.of(2081, 2, 15));
console.log(day.isPublicHoliday); // true
console.log(day.tithi?.en); // "Panchami"
console.log(day.events.map((event) => event.en)); // ["Republic Day"]

info() never fails: a day without data returns the shared empty object (tithi: null, isPublicHoliday: false, events: []). coverage() gives the range with any data and publicHolidays() yields the holiday dates in ascending order.

Topic Where
Every exported name docs/API.md
Speed and bundle size, with the C# baseline docs/benchmarks.md
What changed CHANGELOG.md
Source sanamhub/nepdate-typescript

The converter on the home page runs nepdate-core in your browser.