nepali-heroui-calendar
v1.1.0
Published
Nepali (Bikram Sambat) calendar adapter for @internationalized/date and HeroUI Calendar
Maintainers
Readme
nepali-heroui-calendar
A custom Bikram Sambat (BS) calendar adapter for
@internationalized/date
and HeroUI / React Aria <Calendar> components.
Instead of re-implementing date maths from scratch, this package bridges
Adobe's calendar primitives with the battle-tested lookup tables in
nepali-date-converter.
Heads-up: Because the converter is table-driven, the supported range is 2000–2090 BS (≈ 1943 Apr – 2034 Apr AD). Dates outside this range will throw.
Installation
npm install nepali-heroui-calendarPeer dependencies (your project should already have them if you use HeroUI):
npm install react react-dom @heroui/react @internationalized/dateUsage
1. Drop-in HeroUI Calendar
import { NepaliCalendar, todayNepali } from "nepali-heroui-calendar";
export default function App() {
return (
<NepaliCalendar
aria-label="Nepali Date"
defaultValue={todayNepali()}
/>
);
}2. Use the adapter directly with @internationalized/date
import { CalendarDate, toCalendar, today, getLocalTimeZone } from "@internationalized/date";
import { NepaliCalendarAdapter } from "nepali-heroui-calendar";
const nepali = new NepaliCalendarAdapter();
// Create a BS date
const bsDate = new CalendarDate(nepali, "BS", 2081, 5, 15);
// Convert gregorian "today" to BS
const gToday = today(getLocalTimeZone());
const bsToday = toCalendar(gToday, nepali);
console.log(bsToday.toString()); // 2081-05-153. Lower-level helpers
import {
createCalendarDate,
toNepaliDate,
formatDate,
toNepaliNumerals,
NEPALI_MONTHS,
} from "nepali-heroui-calendar";
const d = createCalendarDate(2081, 1, 15);
// format with nepali-date-converter patterns
formatDate(d, "ddd DD, MMMM YYYY"); // "Saturday 15, Baisakh 2081"
// convert to a NepaliDate instance (from nepali-date-converter)
const nd = toNepaliDate(d);
nd.format("YYYY/MM/DD", "np"); // "२०८१/०१/१५"
toNepaliNumerals(2081); // "२०८१"API
NepaliCalendarAdapter (class)
Implements the Calendar interface from @internationalized/date.
| Method | Description |
| ------------------- | ----------------------------------------------------- |
| fromJulianDay(jd) | JD → BS CalendarDate |
| toJulianDay(date) | BS AnyCalendarDate → JD |
| getDaysInMonth(d) | Days in that BS month (looked up from converter) |
| getMonthsInYear() | Always 12 |
| getYearsInEra() | 2090 (last supported year) |
| getEras() | ["BS"] |
NepaliCalendar (React component)
A thin wrapper around HeroUI's <Calendar> that pre-binds the Nepali adapter.
Accepts all CalendarProps except calendar.
Helpers
| Helper | Return type | Description |
| ------------------ | ----------- | ---------------------------------- |
| todayNepali() | CalendarDate | Today's date in BS |
| createCalendarDate(y,m,d) | CalendarDate | BS CalendarDate factory |
| toNepaliDate(d) | NepaliDate | Convert to converter instance |
| formatDate(d,fmt)| string | Format via converter |
| toNepaliNumerals()| string | 0–9 → Nepali digits |
Limitations & Caveats
- Supported range: 2000–2090 BS. The adapter throws outside this range.
- No CLDR identifier:
"nepali"is not a standardCalendarIdentifier, socreateCalendar("nepali")won't work. Always instantiate the class directly:new NepaliCalendarAdapter(). - Heading text: HeroUI's
<CalendarHeading>currently renders in the active locale using@internationalized/date'sDateFormatter, which does not know Nepali month names. If you need Nepali month labels in the header you can compose your own heading with theuseNepaliMonthLabels()hook.
License
MIT
