@manojshrestha/nepali-date
Version:
Lightweight TypeScript library for Nepali date conversion and date-picking
1,074 lines (1,051 loc) • 43.4 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var require$$0 = require('react');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
/**
* Nepali calendar data constants
*/
// First day of 1970 BS (April 13, 1913 AD)
const BS_EPOCH_DATE = new Date(1913, 3, 13);
// BS 1970 to 2100 - Days in each month for each year
// This is the core data structure that enables accurate BS<->AD conversion
// First array element is for year 1970 BS, each sub-array represents months 1-12
// Format: [Year, [Month1Days, Month2Days, ..., Month12Days]]
const BS_CALENDAR_DATA = [
[1970, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[1971, [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30]],
[1972, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30]],
[1973, [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31]],
[1974, [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30]],
[1975, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[1976, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[1977, [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31]],
[1978, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[1979, [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[1980, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[1981, [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31]],
[1982, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[1983, [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[1984, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[1985, [30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31]],
[1986, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[1987, [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[1988, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[1989, [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30]],
[1990, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[1991, [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[1992, [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31]],
[1993, [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30]],
[1994, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[1995, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30]],
[1996, [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31]],
[1997, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[1998, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[1999, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[2000, [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31]],
[2001, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2002, [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[2003, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[2004, [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31]],
[2005, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2006, [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[2007, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[2008, [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31]],
[2009, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2010, [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[2011, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[2012, [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30]],
[2013, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2014, [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[2015, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[2016, [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30]],
[2017, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2018, [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[2019, [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31]],
[2020, [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30]],
[2021, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2022, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30]],
[2023, [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31]],
[2024, [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30]],
[2025, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2026, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[2027, [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31]],
[2028, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2029, [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[2030, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[2031, [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31]],
[2032, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2033, [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[2034, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[2035, [30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31]],
[2036, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2037, [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[2038, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[2039, [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30]],
[2040, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2041, [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[2042, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[2043, [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30]],
[2044, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2045, [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[2046, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[2047, [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30]],
[2048, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2049, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30]],
[2050, [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31]],
[2051, [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30]],
[2052, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2053, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30]],
[2054, [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31]],
[2055, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2056, [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30]],
[2057, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[2058, [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31]],
[2059, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2060, [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[2061, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[2062, [30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31]],
[2063, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2064, [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[2065, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[2066, [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31]],
[2067, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2068, [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[2069, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[2070, [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30]],
[2071, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2072, [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[2073, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31]],
[2074, [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30]],
[2075, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2076, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30]],
[2077, [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31]],
[2078, [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30]], [2079, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]],
[2080, [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30]],
[2081, [31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30]],
[2082, [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30]],
[2083, [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30]],
[2084, [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30]],
[2085, [31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30]],
[2086, [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30]],
[2087, [31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30]],
[2088, [30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30]],
[2089, [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30]],
[2090, [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30]],
[2091, [31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30]],
[2092, [31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30]],
[2093, [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30]],
[2094, [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30]],
[2095, [31, 31, 32, 31, 31, 31, 30, 29, 30, 30, 30, 30]],
[2096, [30, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30]],
[2097, [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30]],
[2098, [31, 31, 32, 31, 31, 31, 29, 30, 29, 30, 30, 31]],
[2099, [31, 31, 32, 31, 31, 31, 30, 29, 29, 30, 30, 30]],
[2100, [31, 32, 31, 32, 30, 31, 30, 29, 30, 29, 30, 30]]
];
// Month names in English and Nepali
const MONTHS = [
{ en: 'Baisakh', ne: 'बैशाख', days: 31 },
{ en: 'Jestha', ne: 'जेठ', days: 31 },
{ en: 'Ashadh', ne: 'असार', days: 32 },
{ en: 'Shrawan', ne: 'श्रावण', days: 32 },
{ en: 'Bhadra', ne: 'भाद्र', days: 31 },
{ en: 'Ashwin', ne: 'आश्विन', days: 31 },
{ en: 'Kartik', ne: 'कार्तिक', days: 30 },
{ en: 'Mangsir', ne: 'मंसिर', days: 30 },
{ en: 'Poush', ne: 'पौष', days: 30 },
{ en: 'Magh', ne: 'माघ', days: 29 },
{ en: 'Falgun', ne: 'फाल्गुन', days: 30 },
{ en: 'Chaitra', ne: 'चैत्र', days: 30 }
];
// Day names in English and Nepali
const DAYS = {
en: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
ne: ['आइतबार', 'सोमबार', 'मंगलबार', 'बुधबार', 'बिहिबार', 'शुक्रबार', 'शनिबार']
};
// Short day names
const SHORT_DAYS = {
en: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
ne: ['आइत', 'सोम', 'मंगल', 'बुध', 'बिहि', 'शुक्र', 'शनि']
};
// Minimum and maximum supported BS years
const MIN_BS_YEAR = 1970;
const MAX_BS_YEAR = 2100;
/**
* Core date conversion utilities
*/
/**
* Checks if a BS date is valid
* @param bsDate The BS date to validate
* @returns True if valid, false otherwise
*/
function isValidBsDate(bsDate) {
const { year, month, day } = bsDate;
// Check year is within supported range
if (year < MIN_BS_YEAR || year > MAX_BS_YEAR) {
return false;
}
// Check month is valid (1-12)
if (month < 1 || month > 12) {
return false;
}
// Get days in the month for that year
const daysInMonth = getDaysInBsMonth(year, month);
// Check day is valid for the month
if (day < 1 || day > daysInMonth) {
return false;
}
return true;
}
/**
* Checks if a year is a leap year in the Gregorian calendar
* @param year The AD year to check
* @returns True if leap year, false otherwise
*/
function isLeapYear(year) {
return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0);
}
/**
* Gets the number of days in the specified BS month
* @param bsYear The BS year
* @param bsMonth The BS month (1-12)
* @returns Number of days in the month
*/
function getDaysInBsMonth(bsYear, bsMonth) {
if (bsYear < MIN_BS_YEAR || bsYear > MAX_BS_YEAR) {
throw new Error(`Year should be between ${MIN_BS_YEAR} and ${MAX_BS_YEAR}`);
}
if (bsMonth < 1 || bsMonth > 12) {
throw new Error('Month should be between 1 and 12');
}
// Find the year data in our calendar data
const yearData = BS_CALENDAR_DATA.find(data => data[0] === bsYear);
if (!yearData) {
throw new Error(`No data available for year ${bsYear}`);
}
// Return the days in the specified month (adjusting for 0-based array)
return yearData[1][bsMonth - 1];
}
/**
* Convert BS date to AD date
* @param bsDate The BS date to convert
* @returns The equivalent AD date
*/
function bsToAd(bsDate) {
if (!isValidBsDate(bsDate)) {
throw new Error('Invalid BS date');
}
const { year, month, day } = bsDate;
// Calculate days since epoch (BS 1970-01-01)
let daysSinceEpoch = 0;
// Add days for all years from MIN_BS_YEAR to year-1
for (let y = MIN_BS_YEAR; y < year; y++) {
const yearData = BS_CALENDAR_DATA.find(data => data[0] === y);
if (yearData) {
// Sum all the days in this year
daysSinceEpoch += yearData[1].reduce((acc, days) => acc + days, 0);
}
}
// Add days for all months from 1 to month-1 in the current year
const yearData = BS_CALENDAR_DATA.find(data => data[0] === year);
if (yearData) {
for (let m = 0; m < month - 1; m++) {
daysSinceEpoch += yearData[1][m];
}
}
// Add days in the current month
daysSinceEpoch += day - 1;
// Calculate the equivalent AD date
const adDate = new Date(BS_EPOCH_DATE);
adDate.setDate(adDate.getDate() + daysSinceEpoch);
return {
year: adDate.getFullYear(),
month: adDate.getMonth() + 1, // JavaScript months are 0-based
day: adDate.getDate()
};
}
/**
* Convert AD date to BS date
* @param adDate The AD date to convert
* @returns The equivalent BS date
*/
function adToBs(adDate) {
const { year, month, day } = adDate;
// Create a JavaScript Date object
const jsDate = new Date(year, month - 1, day);
// Calculate days since epoch (BS_EPOCH_DATE)
const epochDate = new Date(BS_EPOCH_DATE);
const daysSinceEpoch = Math.floor((jsDate.getTime() - epochDate.getTime()) / (1000 * 60 * 60 * 24));
if (daysSinceEpoch < 0) {
throw new Error('Date is before the minimum supported date');
}
// Find the BS date by counting days from the epoch
let bsYear = MIN_BS_YEAR;
let bsMonth = 1;
let bsDay = 1;
let daysCount = 0;
// Find the year
let yearIndex = 0;
while (yearIndex < BS_CALENDAR_DATA.length) {
const yearData = BS_CALENDAR_DATA[yearIndex];
const daysInYear = yearData[1].reduce((acc, days) => acc + days, 0);
if (daysCount + daysInYear > daysSinceEpoch) {
break;
}
daysCount += daysInYear;
bsYear++;
yearIndex++;
}
// Find the month
const yearData = BS_CALENDAR_DATA.find(data => data[0] === bsYear);
if (yearData) {
let monthIndex = 0;
while (monthIndex < 12) {
const daysInMonth = yearData[1][monthIndex];
if (daysCount + daysInMonth > daysSinceEpoch) {
break;
}
daysCount += daysInMonth;
bsMonth++;
monthIndex++;
}
}
// Calculate the day
bsDay = daysSinceEpoch - daysCount + 1;
return { year: bsYear, month: bsMonth, day: bsDay };
}
/**
* Convert between BS and AD dates
* @param date Either a BS or AD date
* @param calendar The calendar type of the input date ('BS' or 'AD')
* @returns Both BS and AD dates
*/
function convertDate(date, calendar) {
if (calendar === 'BS') {
const bsDate = date;
const adDate = bsToAd(bsDate);
return { bs: bsDate, ad: adDate };
}
else {
const adDate = date;
const bsDate = adToBs(adDate);
return { bs: bsDate, ad: adDate };
}
}
/**
* Date formatting utilities
*/
/**
* Format a BS date according to the given format string
* @param date The BS date to format
* @param format The format string
* @param locale The locale to use ('en' or 'ne')
* @returns The formatted date string
*/
function formatBsDate(date, format = 'YYYY-MM-DD', locale = 'en') {
const { year, month, day } = date;
// Month and day names
const monthName = MONTHS[month - 1][locale];
const monthShort = monthName.substring(0, 3);
const dayOfWeek = getDayOfWeek(date);
const dayName = DAYS[locale][dayOfWeek];
const dayNameShort = SHORT_DAYS[locale][dayOfWeek];
// Replace tokens in the format string
return format
.replace(/YYYY/g, year.toString())
.replace(/YY/g, (year % 100).toString().padStart(2, '0'))
.replace(/MMMM/g, monthName)
.replace(/MMM/g, monthShort)
.replace(/MM/g, month.toString().padStart(2, '0'))
.replace(/M/g, month.toString())
.replace(/DD/g, day.toString().padStart(2, '0'))
.replace(/D/g, day.toString())
.replace(/dddd/g, dayName)
.replace(/ddd/g, dayNameShort)
.replace(/d/g, dayOfWeek.toString());
}
/**
* Format an AD date according to the given format string
* @param date The AD date to format
* @param format The format string
* @param locale The locale to use ('en' or 'ne')
* @returns The formatted date string
*/
function formatAdDate(date, format = 'YYYY-MM-DD', locale = 'en') {
const { year, month, day } = date;
// Create a JavaScript Date object
const jsDate = new Date(year, month - 1, day);
// Get day of week (0-6, Sunday-Saturday)
const dayOfWeek = jsDate.getDay();
// Month names in English
const monthNames = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
];
// Short month names
const monthNamesShort = monthNames.map(m => m.substring(0, 3));
// Replace tokens in the format string
return format
.replace(/YYYY/g, year.toString())
.replace(/YY/g, (year % 100).toString().padStart(2, '0'))
.replace(/MMMM/g, monthNames[month - 1])
.replace(/MMM/g, monthNamesShort[month - 1])
.replace(/MM/g, month.toString().padStart(2, '0'))
.replace(/M/g, month.toString())
.replace(/DD/g, day.toString().padStart(2, '0'))
.replace(/D/g, day.toString())
.replace(/dddd/g, DAYS.en[dayOfWeek])
.replace(/ddd/g, SHORT_DAYS.en[dayOfWeek])
.replace(/d/g, dayOfWeek.toString());
}
/**
* Get the day of week (0-6, Sunday-Saturday) for a BS date
* @param date The BS date
* @returns The day of week (0-6)
*/
function getDayOfWeek(date) {
// To get the day of week, we convert to AD and use the JavaScript Date object
const jsDate = new Date(date.year, date.month - 1, date.day);
return jsDate.getDay();
}
/**
* Detect the user's locale
* @returns The detected locale ('ne' or 'en' default)
*/
function detectLocale() {
if (typeof navigator !== 'undefined') {
const lang = navigator.language || navigator.userLanguage;
if (lang && lang.startsWith('ne')) {
return 'ne';
}
}
return 'en';
}
var jsxRuntime = {exports: {}};
var reactJsxRuntime_production = {};
/**
* @license React
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var hasRequiredReactJsxRuntime_production;
function requireReactJsxRuntime_production () {
if (hasRequiredReactJsxRuntime_production) return reactJsxRuntime_production;
hasRequiredReactJsxRuntime_production = 1;
var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
function jsxProd(type, config, maybeKey) {
var key = null;
void 0 !== maybeKey && (key = "" + maybeKey);
void 0 !== config.key && (key = "" + config.key);
if ("key" in config) {
maybeKey = {};
for (var propName in config)
"key" !== propName && (maybeKey[propName] = config[propName]);
} else maybeKey = config;
config = maybeKey.ref;
return {
$$typeof: REACT_ELEMENT_TYPE,
type: type,
key: key,
ref: void 0 !== config ? config : null,
props: maybeKey
};
}
reactJsxRuntime_production.Fragment = REACT_FRAGMENT_TYPE;
reactJsxRuntime_production.jsx = jsxProd;
reactJsxRuntime_production.jsxs = jsxProd;
return reactJsxRuntime_production;
}
var reactJsxRuntime_development = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var hasRequiredReactJsxRuntime_development;
function requireReactJsxRuntime_development () {
if (hasRequiredReactJsxRuntime_development) return reactJsxRuntime_development;
hasRequiredReactJsxRuntime_development = 1;
"production" !== process.env.NODE_ENV &&
(function () {
function getComponentNameFromType(type) {
if (null == type) return null;
if ("function" === typeof type)
return type.$$typeof === REACT_CLIENT_REFERENCE
? null
: type.displayName || type.name || null;
if ("string" === typeof type) return type;
switch (type) {
case REACT_FRAGMENT_TYPE:
return "Fragment";
case REACT_PROFILER_TYPE:
return "Profiler";
case REACT_STRICT_MODE_TYPE:
return "StrictMode";
case REACT_SUSPENSE_TYPE:
return "Suspense";
case REACT_SUSPENSE_LIST_TYPE:
return "SuspenseList";
case REACT_ACTIVITY_TYPE:
return "Activity";
}
if ("object" === typeof type)
switch (
("number" === typeof type.tag &&
console.error(
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
),
type.$$typeof)
) {
case REACT_PORTAL_TYPE:
return "Portal";
case REACT_CONTEXT_TYPE:
return (type.displayName || "Context") + ".Provider";
case REACT_CONSUMER_TYPE:
return (type._context.displayName || "Context") + ".Consumer";
case REACT_FORWARD_REF_TYPE:
var innerType = type.render;
type = type.displayName;
type ||
((type = innerType.displayName || innerType.name || ""),
(type = "" !== type ? "ForwardRef(" + type + ")" : "ForwardRef"));
return type;
case REACT_MEMO_TYPE:
return (
(innerType = type.displayName || null),
null !== innerType
? innerType
: getComponentNameFromType(type.type) || "Memo"
);
case REACT_LAZY_TYPE:
innerType = type._payload;
type = type._init;
try {
return getComponentNameFromType(type(innerType));
} catch (x) {}
}
return null;
}
function testStringCoercion(value) {
return "" + value;
}
function checkKeyStringCoercion(value) {
try {
testStringCoercion(value);
var JSCompiler_inline_result = !1;
} catch (e) {
JSCompiler_inline_result = !0;
}
if (JSCompiler_inline_result) {
JSCompiler_inline_result = console;
var JSCompiler_temp_const = JSCompiler_inline_result.error;
var JSCompiler_inline_result$jscomp$0 =
("function" === typeof Symbol &&
Symbol.toStringTag &&
value[Symbol.toStringTag]) ||
value.constructor.name ||
"Object";
JSCompiler_temp_const.call(
JSCompiler_inline_result,
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
JSCompiler_inline_result$jscomp$0
);
return testStringCoercion(value);
}
}
function getTaskName(type) {
if (type === REACT_FRAGMENT_TYPE) return "<>";
if (
"object" === typeof type &&
null !== type &&
type.$$typeof === REACT_LAZY_TYPE
)
return "<...>";
try {
var name = getComponentNameFromType(type);
return name ? "<" + name + ">" : "<...>";
} catch (x) {
return "<...>";
}
}
function getOwner() {
var dispatcher = ReactSharedInternals.A;
return null === dispatcher ? null : dispatcher.getOwner();
}
function UnknownOwner() {
return Error("react-stack-top-frame");
}
function hasValidKey(config) {
if (hasOwnProperty.call(config, "key")) {
var getter = Object.getOwnPropertyDescriptor(config, "key").get;
if (getter && getter.isReactWarning) return !1;
}
return void 0 !== config.key;
}
function defineKeyPropWarningGetter(props, displayName) {
function warnAboutAccessingKey() {
specialPropKeyWarningShown ||
((specialPropKeyWarningShown = !0),
console.error(
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
displayName
));
}
warnAboutAccessingKey.isReactWarning = !0;
Object.defineProperty(props, "key", {
get: warnAboutAccessingKey,
configurable: !0
});
}
function elementRefGetterWithDeprecationWarning() {
var componentName = getComponentNameFromType(this.type);
didWarnAboutElementRef[componentName] ||
((didWarnAboutElementRef[componentName] = !0),
console.error(
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
));
componentName = this.props.ref;
return void 0 !== componentName ? componentName : null;
}
function ReactElement(
type,
key,
self,
source,
owner,
props,
debugStack,
debugTask
) {
self = props.ref;
type = {
$$typeof: REACT_ELEMENT_TYPE,
type: type,
key: key,
props: props,
_owner: owner
};
null !== (void 0 !== self ? self : null)
? Object.defineProperty(type, "ref", {
enumerable: !1,
get: elementRefGetterWithDeprecationWarning
})
: Object.defineProperty(type, "ref", { enumerable: !1, value: null });
type._store = {};
Object.defineProperty(type._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: 0
});
Object.defineProperty(type, "_debugInfo", {
configurable: !1,
enumerable: !1,
writable: !0,
value: null
});
Object.defineProperty(type, "_debugStack", {
configurable: !1,
enumerable: !1,
writable: !0,
value: debugStack
});
Object.defineProperty(type, "_debugTask", {
configurable: !1,
enumerable: !1,
writable: !0,
value: debugTask
});
Object.freeze && (Object.freeze(type.props), Object.freeze(type));
return type;
}
function jsxDEVImpl(
type,
config,
maybeKey,
isStaticChildren,
source,
self,
debugStack,
debugTask
) {
var children = config.children;
if (void 0 !== children)
if (isStaticChildren)
if (isArrayImpl(children)) {
for (
isStaticChildren = 0;
isStaticChildren < children.length;
isStaticChildren++
)
validateChildKeys(children[isStaticChildren]);
Object.freeze && Object.freeze(children);
} else
console.error(
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
);
else validateChildKeys(children);
if (hasOwnProperty.call(config, "key")) {
children = getComponentNameFromType(type);
var keys = Object.keys(config).filter(function (k) {
return "key" !== k;
});
isStaticChildren =
0 < keys.length
? "{key: someKey, " + keys.join(": ..., ") + ": ...}"
: "{key: someKey}";
didWarnAboutKeySpread[children + isStaticChildren] ||
((keys =
0 < keys.length ? "{" + keys.join(": ..., ") + ": ...}" : "{}"),
console.error(
'A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',
isStaticChildren,
children,
keys,
children
),
(didWarnAboutKeySpread[children + isStaticChildren] = !0));
}
children = null;
void 0 !== maybeKey &&
(checkKeyStringCoercion(maybeKey), (children = "" + maybeKey));
hasValidKey(config) &&
(checkKeyStringCoercion(config.key), (children = "" + config.key));
if ("key" in config) {
maybeKey = {};
for (var propName in config)
"key" !== propName && (maybeKey[propName] = config[propName]);
} else maybeKey = config;
children &&
defineKeyPropWarningGetter(
maybeKey,
"function" === typeof type
? type.displayName || type.name || "Unknown"
: type
);
return ReactElement(
type,
children,
self,
source,
getOwner(),
maybeKey,
debugStack,
debugTask
);
}
function validateChildKeys(node) {
"object" === typeof node &&
null !== node &&
node.$$typeof === REACT_ELEMENT_TYPE &&
node._store &&
(node._store.validated = 1);
}
var React = require$$0__default["default"],
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"),
REACT_PROFILER_TYPE = Symbol.for("react.profiler");
var REACT_CONSUMER_TYPE = Symbol.for("react.consumer"),
REACT_CONTEXT_TYPE = Symbol.for("react.context"),
REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"),
REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"),
REACT_SUSPENSE_LIST_TYPE = Symbol.for("react.suspense_list"),
REACT_MEMO_TYPE = Symbol.for("react.memo"),
REACT_LAZY_TYPE = Symbol.for("react.lazy"),
REACT_ACTIVITY_TYPE = Symbol.for("react.activity"),
REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"),
ReactSharedInternals =
React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
hasOwnProperty = Object.prototype.hasOwnProperty,
isArrayImpl = Array.isArray,
createTask = console.createTask
? console.createTask
: function () {
return null;
};
React = {
"react-stack-bottom-frame": function (callStackForError) {
return callStackForError();
}
};
var specialPropKeyWarningShown;
var didWarnAboutElementRef = {};
var unknownOwnerDebugStack = React["react-stack-bottom-frame"].bind(
React,
UnknownOwner
)();
var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
var didWarnAboutKeySpread = {};
reactJsxRuntime_development.Fragment = REACT_FRAGMENT_TYPE;
reactJsxRuntime_development.jsx = function (type, config, maybeKey, source, self) {
var trackActualOwner =
1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
return jsxDEVImpl(
type,
config,
maybeKey,
!1,
source,
self,
trackActualOwner
? Error("react-stack-top-frame")
: unknownOwnerDebugStack,
trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask
);
};
reactJsxRuntime_development.jsxs = function (type, config, maybeKey, source, self) {
var trackActualOwner =
1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
return jsxDEVImpl(
type,
config,
maybeKey,
!0,
source,
self,
trackActualOwner
? Error("react-stack-top-frame")
: unknownOwnerDebugStack,
trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask
);
};
})();
return reactJsxRuntime_development;
}
var hasRequiredJsxRuntime;
function requireJsxRuntime () {
if (hasRequiredJsxRuntime) return jsxRuntime.exports;
hasRequiredJsxRuntime = 1;
if (process.env.NODE_ENV === 'production') {
jsxRuntime.exports = requireReactJsxRuntime_production();
} else {
jsxRuntime.exports = requireReactJsxRuntime_development();
}
return jsxRuntime.exports;
}
var jsxRuntimeExports = requireJsxRuntime();
/**
* NepaliDatePicker component for React
*/
const NepaliDatePicker = ({ value, defaultCalendar = 'BS', minDate, maxDate, disabledDays = [], holidays = [], locale = detectLocale(), theme = 'light', onChange, className = '', }) => {
// Current calendar mode (BS or AD)
const [currentCalendar, setCurrentCalendar] = require$$0.useState(defaultCalendar);
// Current view date (the month being displayed)
const [viewDate, setViewDate] = require$$0.useState(() => {
// Default to current date if no value provided
if (!value) {
const today = new Date();
const adDate = {
year: today.getFullYear(),
month: today.getMonth() + 1,
day: today.getDate(),
};
const bsDate = adToBs(adDate);
return { bs: bsDate, ad: adDate };
}
// Convert the provided value to both calendars
if (defaultCalendar === 'BS') {
const bsDate = value;
const adDate = bsToAd(bsDate);
return { bs: bsDate, ad: adDate };
}
else {
const adDate = value;
const bsDate = adToBs(adDate);
return { bs: bsDate, ad: adDate };
}
});
// Selected date
const [selectedDate, setSelectedDate] = require$$0.useState(value ? (currentCalendar === 'BS'
? { bs: value, ad: bsToAd(value) }
: { bs: adToBs(value), ad: value })
: null);
// Month calendar data
const [calendarDays, setCalendarDays] = require$$0.useState([]);
// Effects
// Update calendar days when view date changes
require$$0.useEffect(() => {
if (currentCalendar === 'BS') {
generateBSCalendarDays(viewDate.bs);
}
else {
generateADCalendarDays(viewDate.ad);
}
}, [viewDate, currentCalendar]);
// Generate BS calendar days
const generateBSCalendarDays = (date) => {
const { year, month } = date;
const daysInMonth = getDaysInBsMonth(year, month);
// Get the first day of the month
const firstDay = new Date(bsToAd({ year, month, day: 1 }).year, bsToAd({ year, month, day: 1 }).month - 1, bsToAd({ year, month, day: 1 }).day).getDay();
const days = [];
// Add empty slots for days before the first day of the month
for (let i = 0; i < firstDay; i++) {
days.push(null);
}
// Add the days of the month
for (let i = 1; i <= daysInMonth; i++) {
days.push({ year, month, day: i });
}
setCalendarDays(days);
};
// Generate AD calendar days
const generateADCalendarDays = (date) => {
const { year, month } = date;
// Calculate days in month for AD
const daysInMonth = new Date(year, month, 0).getDate();
// Get the first day of the month
const firstDay = new Date(year, month - 1, 1).getDay();
const days = [];
// Add empty slots for days before the first day of the month
for (let i = 0; i < firstDay; i++) {
days.push(null);
}
// Add the days of the month (converting to BS for consistency in the component)
for (let i = 1; i <= daysInMonth; i++) {
days.push(adToBs({ year, month, day: i }));
}
setCalendarDays(days);
};
// Change the month being viewed
const changeMonth = (delta) => {
if (currentCalendar === 'BS') {
let newMonth = viewDate.bs.month + delta;
let newYear = viewDate.bs.year;
if (newMonth > 12) {
newMonth = 1;
newYear += 1;
}
else if (newMonth < 1) {
newMonth = 12;
newYear -= 1;
}
const newBsDate = { year: newYear, month: newMonth, day: 1 };
if (isValidBsDate(newBsDate)) {
const newAdDate = bsToAd(newBsDate);
setViewDate({ bs: newBsDate, ad: newAdDate });
}
}
else {
let newMonth = viewDate.ad.month + delta;
let newYear = viewDate.ad.year;
if (newMonth > 12) {
newMonth = 1;
newYear += 1;
}
else if (newMonth < 1) {
newMonth = 12;
newYear -= 1;
}
const newAdDate = { year: newYear, month: newMonth, day: 1 };
const newBsDate = adToBs(newAdDate);
setViewDate({ bs: newBsDate, ad: newAdDate });
}
};
// Select a date
const selectDate = (date) => {
if (!date)
return;
const adDate = bsToAd(date);
const newDateConversion = { bs: date, ad: adDate };
setSelectedDate(newDateConversion);
if (onChange) {
onChange(newDateConversion);
}
};
// Check if a date is disabled
const isDateDisabled = (date) => {
if (!date)
return true;
// Convert to AD for comparison
const adDate = bsToAd(date);
// Check if the day of week is disabled
const dayOfWeek = new Date(adDate.year, adDate.month - 1, adDate.day).getDay();
if (disabledDays.includes(dayOfWeek)) {
return true;
}
// Check if the date is a holiday
const isHoliday = holidays.some(holiday => {
if ('year' in holiday && 'month' in holiday && 'day' in holiday) {
// If it's a BS date
if ('year' in holiday && 'month' in holiday && 'day' in holiday) {
if (holiday.year === date.year &&
holiday.month === date.month &&
holiday.day === date.day) {
return true;
}
}
}
return false;
});
if (isHoliday) {
return true;
}
// Check min date
if (minDate) {
const minBsDate = currentCalendar === 'BS' ? minDate : adToBs(minDate);
if (date.year < minBsDate.year ||
(date.year === minBsDate.year && date.month < minBsDate.month) ||
(date.year === minBsDate.year && date.month === minBsDate.month && date.day < minBsDate.day)) {
return true;
}
}
// Check max date
if (maxDate) {
const maxBsDate = currentCalendar === 'BS' ? maxDate : adToBs(maxDate);
if (date.year > maxBsDate.year ||
(date.year === maxBsDate.year && date.month > maxBsDate.month) ||
(date.year === maxBsDate.year && date.month === maxBsDate.month && date.day > maxBsDate.day)) {
return true;
}
}
return false;
};
// Get the month and year display for the current view
const getMonthYearDisplay = () => {
if (currentCalendar === 'BS') {
return `${MONTHS[viewDate.bs.month - 1][locale]} ${viewDate.bs.year}`;
}
else {
const monthNames = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
];
return `${monthNames[viewDate.ad.month - 1]} ${viewDate.ad.year}`;
}
};
// Render
return (jsxRuntimeExports.jsxs("div", { className: `nepali-date-picker ${className} theme-${theme}`, children: [jsxRuntimeExports.jsxs("div", { className: "calendar-header", children: [jsxRuntimeExports.jsx("button", { onClick: () => changeMonth(-1), className: "prev-month", children: "<" }), jsxRuntimeExports.jsx("div", { className: "month-year", children: getMonthYearDisplay() }), jsxRuntimeExports.jsx("button", { onClick: () => changeMonth(1), className: "next-month", children: ">" })] }), jsxRuntimeExports.jsxs("div", { className: "calendar-mode-toggle", children: [jsxRuntimeExports.jsx("button", { className: currentCalendar === 'BS' ? 'active' : '', onClick: () => setCurrentCalendar('BS'), children: "BS" }), jsxRuntimeExports.jsx("button", { className: currentCalendar === 'AD' ? 'active' : '', onClick: () => setCurrentCalendar('AD'), children: "AD" })] }), jsxRuntimeExports.jsx("div", { className: "weekdays", children: SHORT_DAYS[locale].map((day, index) => (jsxRuntimeExports.jsx("div", { className: "weekday", children: day }, index))) }), jsxRuntimeExports.jsx("div", { className: "days", children: calendarDays.map((date, index) => (jsxRuntimeExports.jsx("div", { className: `day ${!date ? 'empty' : ''} ${isDateDisabled(date) ? 'disabled' : ''} ${selectedDate && date &&
selectedDate.bs.year === date.year &&
selectedDate.bs.month === date.month &&
selectedDate.bs.day === date.day ? 'selected' : ''}`, onClick: () => !isDateDisabled(date) && selectDate(date), children: date ? date.day : '' }, index))) }), selectedDate && (jsxRuntimeExports.jsxs("div", { className: "selected-date-display", children: [jsxRuntimeExports.jsxs("div", { className: "bs-date", children: ["BS: ", formatBsDate(selectedDate.bs, 'YYYY-MM-DD', locale)] }), jsxRuntimeExports.jsxs("div", { className: "ad-date", children: ["AD: ", formatAdDate(selectedDate.ad, 'YYYY-MM-DD', locale)] })] }))] }));
};
exports.BS_EPOCH_DATE = BS_EPOCH_DATE;
exports.DAYS = DAYS;
exports.MAX_BS_YEAR = MAX_BS_YEAR;
exports.MIN_BS_YEAR = MIN_BS_YEAR;
exports.MONTHS = MONTHS;
exports.NepaliDatePicker = NepaliDatePicker;
exports.SHORT_DAYS = SHORT_DAYS;
exports.adToBs = adToBs;
exports.bsToAd = bsToAd;
exports.convertDate = convertDate;
exports.detectLocale = detectLocale;
exports.formatAdDate = formatAdDate;
exports.formatBsDate = formatBsDate;
exports.getDaysInBsMonth = getDaysInBsMonth;
exports.isLeapYear = isLeapYear;
exports.isValidBsDate = isValidBsDate;
//# sourceMappingURL=index.cjs.js.map