@bhuwan_darai/nepali-date-react
v0.2.0
Published
Nepali BS and Gregorian AD calendar conversion with a reusable React date picker.
Readme
nepali-date-react
A reusable Nepali Bikram Sambat (BS) date picker for ordinary React forms. No React Hook Form or Formik required.
Data range: BS 1975–2084 (1918-04-13 through 2028-04-13 AD). The 1975–2083 month-length rows are supplied as corroborated calendar data; 2084 is a provisional projection and must be reconfirmed against the official Panchanga. Year starts are chained from the anchor 1 Baisakh 2083 = 2026-04-14 using the supplied annual month lengths. Dates outside the bundled range throw an error. Do not use provisional dates for legal or official records without independent confirmation.
Install
npm install nepali-date-reactNormal HTML form
import { useState } from "react";
import { NepaliDatePicker } from "nepali-date-react";
import "nepali-date-react/styles.css";
export function RegistrationForm() {
const [dob, setDob] = useState("");
function submit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
const form = new FormData(event.currentTarget);
console.log(form.get("dateOfBirth"));
}
return <form onSubmit={submit}>
<label htmlFor="dob">Date of birth</label>
<NepaliDatePicker id="dob" name="dateOfBirth" value={dob}
onChange={(value, dates) => { setDob(value); console.log(dates.ad, dates.bs); }}
calendar="BS" language="en" numerals="english" required />
<button type="submit">Submit</button>
</form>;
}The hidden input submits the selected value under name. For calendar="BS", the submitted value is YYYY-MM-DD in BS. The onChange callback also receives both { bs, ad } strings. The calendar dataset covers BS 1975–2084; 2084 is provisional.
Conversion API
import { adToBs, bsToAd, formatBS, getDaysInBSMonth } from "nepali-date-react";
const bs = adToBs("2026-11-04");
const ad = bsToAd({ year: 2083, month: 7, day: 18 });
console.log(formatBS(bs), ad);Props
name(required): HTML form field name.value/defaultValue: selected date string.onChange(value, { bs, ad }): selection callback.calendar:BS(default) orAD.language:en(default) orne.numerals:english(default) ornepali.required,disabled,readOnly,minDate,maxDate,className,error,placeholder,id.
minDate and maxDate are Gregorian YYYY-MM-DD strings. value is in the selected calendar format.
