@nepdatejs/core 0.0.0-bootstrap → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["bsMonths","adMonths","BS_DATA","BS_DATA"],"sources":["../src/errors.ts","../src/epoch.ts","../src/locale/en.ts","../src/locale/ne.ts","../src/locale/registry.ts","../src/config.ts","../src/ad/calendar.ts","../src/bs/table.ts","../src/bs/data-api.ts","../src/create.ts","../src/convert.ts","../src/projected.ts","../src/clock.ts","../src/arithmetic.ts","../src/compare.ts","../src/locale/index.ts","../src/format.ts","../src/fiscal.ts","../src/parse.ts","../src/time.ts"],"sourcesContent":["export type NepDateRangeErrorCode =\n /** The year, month or day does not exist in that calendar. */\n | 'INVALID_DATE'\n /** The date is outside the BS table, so it cannot be a BS date or be converted. */\n | 'OUT_OF_TABLE'\n /** A value of the wrong kind: not an integer, unknown time zone, bad text, … */\n | 'INVALID_ARGUMENT';\n\n/** Thrown for any invalid date or argument. Check `code`, not the message. */\nexport class NepDateRangeError extends RangeError {\n readonly code: NepDateRangeErrorCode;\n\n constructor(code: NepDateRangeErrorCode, message: string) {\n super(message);\n this.name = 'NepDateRangeError';\n this.code = code;\n }\n}\n\nexport type NepDateDataErrorCode =\n 'EMPTY' | 'BAD_MONTH_COUNT' | 'BAD_MONTH' | 'BAD_YEAR_TOTAL' | 'BAD_ANCHOR';\n\n/** Thrown when a BS table passed to `setBsData` or `patchBsYear` is not valid. */\nexport class NepDateDataError extends Error {\n readonly code: NepDateDataErrorCode;\n /** The BS year at fault, when there is one. */\n readonly year: number | undefined;\n /** The month (1–12) at fault, when there is one. */\n readonly month: number | undefined;\n\n constructor(\n code: NepDateDataErrorCode,\n message: string,\n year?: number,\n month?: number,\n ) {\n super(message);\n this.name = 'NepDateDataError';\n this.code = code;\n this.year = year;\n this.month = month;\n }\n}\n","import { NepDateRangeError } from './errors';\nimport type { EpochDay, Weekday } from './types';\n\n/** Brand a whole number of days since 1970-01-01 as an `EpochDay`. */\nexport function toEpochDay(value: number): EpochDay {\n if (!Number.isSafeInteger(value)) {\n throw new NepDateRangeError(\n 'INVALID_ARGUMENT',\n `${String(value)} is not a whole number of days.`,\n );\n }\n\n return value as EpochDay;\n}\n\n/** The weekday of a day count. 1970-01-01 was a Thursday. */\nexport function weekdayOf(epoch: EpochDay): Weekday {\n return ((((epoch + 4) % 7) + 7) % 7) as Weekday;\n}\n","import type { LocaleData } from './registry';\n\nconst bsMonths = [\n 'Baisakh',\n 'Jestha',\n 'Asar',\n 'Shrawan',\n 'Bhadra',\n 'Ashwin',\n 'Kartik',\n 'Mangsir',\n 'Poush',\n 'Magh',\n 'Falgun',\n 'Chaitra',\n];\nconst adMonths = [\n 'January',\n 'February',\n 'March',\n 'April',\n 'May',\n 'June',\n 'July',\n 'August',\n 'September',\n 'October',\n 'November',\n 'December',\n];\n\nexport const en: LocaleData = {\n digits: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],\n weekdays: {\n long: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],\n short: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],\n narrow: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],\n },\n months: {\n AD: { long: adMonths, short: adMonths.map((name) => name.slice(0, 3)) },\n BS: { long: bsMonths, short: bsMonths.map((name) => name.slice(0, 3)) },\n },\n calendarNames: { AD: 'AD', BS: 'BS' },\n labels: {\n today: 'Today',\n clear: 'Clear date',\n previousMonth: 'Previous month',\n nextMonth: 'Next month',\n previousYear: 'Previous year',\n nextYear: 'Next year',\n month: 'Month',\n year: 'Year',\n openCalendar: 'Open calendar',\n chooseDate: 'Choose a date',\n calendar: 'Calendar',\n presets: 'Shortcuts',\n fiscalYear: 'Fiscal year',\n time: 'Time',\n hour: 'Hour',\n minute: 'Minute',\n now: 'Now',\n done: 'Done',\n },\n time: { am: 'AM', pm: 'PM' },\n presets: {\n today: 'Today',\n yesterday: 'Yesterday',\n tomorrow: 'Tomorrow',\n thisWeek: 'This week',\n lastWeek: 'Last week',\n last7Days: 'Last 7 days',\n last30Days: 'Last 30 days',\n thisMonth: 'This month',\n lastMonth: 'Last month',\n thisYear: 'This year',\n thisFiscalYear: 'This fiscal year',\n lastFiscalYear: 'Last fiscal year',\n },\n messages: {\n invalidFormat: {\n AD: 'Enter an AD date as YYYY-MM-DD.',\n BS: 'Enter a BS date as YYYY-MM-DD.',\n },\n outOfRange: 'Choose a date from {min} to {max}.',\n onOrAfter: 'Choose {min} or later.',\n onOrBefore: 'Choose {max} or earlier.',\n unavailable: 'This date is not available.',\n rangeTooShort: 'Choose at least {min} days.',\n rangeTooLong: 'Choose at most {max} days.',\n tooManyDates: 'Choose at most {max} dates.',\n invalidTime: 'Enter a time as HH:MM.',\n },\n};\n","import type { LocaleData } from './registry';\n\nconst bsMonths = [\n 'बैशाख',\n 'जेठ',\n 'असार',\n 'साउन',\n 'भदौ',\n 'असोज',\n 'कार्तिक',\n 'मङ्सिर',\n 'पुस',\n 'माघ',\n 'फाल्गुण',\n 'चैत',\n];\nconst adMonths = [\n 'जनवरी',\n 'फेब्रुअरी',\n 'मार्च',\n 'अप्रिल',\n 'मे',\n 'जुन',\n 'जुलाई',\n 'अगस्ट',\n 'सेप्टेम्बर',\n 'अक्टोबर',\n 'नोभेम्बर',\n 'डिसेम्बर',\n];\n\nexport const ne: LocaleData = {\n digits: ['०', '१', '२', '३', '४', '५', '६', '७', '८', '९'],\n weekdays: {\n long: ['आइतबार', 'सोमबार', 'मङ्गलबार', 'बुधबार', 'बिहिबार', 'शुक्रबार', 'शनिबार'],\n short: ['आइत', 'सोम', 'मङ्गल', 'बुध', 'बिही', 'शुक्र', 'शनि'],\n narrow: ['आ', 'सो', 'मं', 'बु', 'बि', 'शु', 'श'],\n },\n months: {\n AD: { long: adMonths, short: adMonths },\n BS: { long: bsMonths, short: bsMonths },\n },\n calendarNames: { AD: 'ई.सं.', BS: 'वि.सं.' },\n labels: {\n today: 'आज',\n clear: 'मिति हटाउनुहोस्',\n previousMonth: 'अघिल्लो महिना',\n nextMonth: 'अर्को महिना',\n previousYear: 'अघिल्लो वर्ष',\n nextYear: 'अर्को वर्ष',\n month: 'महिना',\n year: 'वर्ष',\n openCalendar: 'पात्रो खोल्नुहोस्',\n chooseDate: 'मिति छान्नुहोस्',\n calendar: 'पात्रो',\n presets: 'छिटो छनोट',\n fiscalYear: 'आर्थिक वर्ष',\n time: 'समय',\n hour: 'घण्टा',\n minute: 'मिनेट',\n now: 'अहिले',\n done: 'भयो',\n },\n time: { am: 'पूर्वाह्न', pm: 'अपराह्न' },\n presets: {\n today: 'आज',\n yesterday: 'हिजो',\n tomorrow: 'भोलि',\n thisWeek: 'यो हप्ता',\n lastWeek: 'गत हप्ता',\n last7Days: 'पछिल्लो ७ दिन',\n last30Days: 'पछिल्लो ३० दिन',\n thisMonth: 'यो महिना',\n lastMonth: 'गत महिना',\n thisYear: 'यो वर्ष',\n thisFiscalYear: 'यो आर्थिक वर्ष',\n lastFiscalYear: 'गत आर्थिक वर्ष',\n },\n messages: {\n invalidFormat: {\n AD: 'ई.सं. मिति YYYY-MM-DD ढाँचामा लेख्नुहोस्।',\n BS: 'वि.सं. मिति YYYY-MM-DD ढाँचामा लेख्नुहोस्।',\n },\n outOfRange: '{min} देखि {max} सम्मको मिति छान्नुहोस्।',\n onOrAfter: '{min} वा त्यसपछिको मिति छान्नुहोस्।',\n onOrBefore: '{max} वा त्यसअघिको मिति छान्नुहोस्।',\n unavailable: 'यो मिति उपलब्ध छैन।',\n rangeTooShort: 'कम्तीमा {min} दिन छान्नुहोस्।',\n rangeTooLong: 'बढीमा {max} दिन छान्नुहोस्।',\n tooManyDates: 'बढीमा {max} मिति छान्नुहोस्।',\n invalidTime: 'समय HH:MM ढाँचामा लेख्नुहोस्।',\n },\n};\n","import { NepDateRangeError } from '../errors';\nimport type { LocaleCode } from '../types';\nimport { en } from './en';\nimport { ne } from './ne';\n\ntype Names12 = readonly string[];\n\n/** Everything a language needs: digits, names, UI labels and validation messages. */\nexport interface LocaleData {\n /** Ten digit characters, 0–9. */\n readonly digits: readonly string[];\n /** Seven names each, Sunday first. */\n readonly weekdays: {\n readonly long: readonly string[];\n readonly short: readonly string[];\n readonly narrow: readonly string[];\n };\n /** Twelve names each, first month first. */\n readonly months: {\n readonly AD: { readonly long: Names12; readonly short: Names12 };\n readonly BS: { readonly long: Names12; readonly short: Names12 };\n };\n /** How each calendar is named in this language: \"BS\" / \"वि.सं.\". */\n readonly calendarNames: { readonly AD: string; readonly BS: string };\n readonly labels: {\n readonly today: string;\n readonly clear: string;\n readonly previousMonth: string;\n readonly nextMonth: string;\n readonly previousYear: string;\n readonly nextYear: string;\n readonly month: string;\n readonly year: string;\n readonly openCalendar: string;\n readonly chooseDate: string;\n readonly calendar: string;\n /** Picker shortcuts (presets) and the name of their list. */\n readonly presets: string;\n readonly fiscalYear: string;\n readonly time: string;\n readonly hour: string;\n readonly minute: string;\n readonly now: string;\n readonly done: string;\n };\n /** Words for 12-hour times. */\n readonly time: { readonly am: string; readonly pm: string };\n /** Names of the built-in picker presets. */\n readonly presets: {\n readonly today: string;\n readonly yesterday: string;\n readonly tomorrow: string;\n readonly thisWeek: string;\n readonly lastWeek: string;\n readonly last7Days: string;\n readonly last30Days: string;\n readonly thisMonth: string;\n readonly lastMonth: string;\n readonly thisYear: string;\n readonly thisFiscalYear: string;\n readonly lastFiscalYear: string;\n };\n /** Messages may use {min} and {max} placeholders. */\n readonly messages: {\n readonly invalidFormat: { readonly AD: string; readonly BS: string };\n readonly outOfRange: string;\n readonly onOrAfter: string;\n readonly onOrBefore: string;\n readonly unavailable: string;\n /** Range pickers: {min} / {max} are day counts. */\n readonly rangeTooShort: string;\n readonly rangeTooLong: string;\n /** Multiple-date pickers: {max} is a count of dates. */\n readonly tooManyDates: string;\n readonly invalidTime: string;\n };\n}\n\nconst locales = new Map<string, LocaleData>([\n ['en', en],\n ['ne', ne],\n]);\n\n/** Add or replace a language. Lists must have the right lengths (10 digits, 7 weekdays, 12 months). */\nexport function registerLocale(code: LocaleCode, data: LocaleData): void {\n const checks: [string, readonly string[], number][] = [\n ['digits', data.digits, 10],\n ['weekdays.long', data.weekdays.long, 7],\n ['weekdays.short', data.weekdays.short, 7],\n ['weekdays.narrow', data.weekdays.narrow, 7],\n ['months.AD.long', data.months.AD.long, 12],\n ['months.AD.short', data.months.AD.short, 12],\n ['months.BS.long', data.months.BS.long, 12],\n ['months.BS.short', data.months.BS.short, 12],\n ];\n for (const [name, list, length] of checks) {\n if (list.length !== length) {\n throw new NepDateRangeError(\n 'INVALID_ARGUMENT',\n `Locale \"${code}\": ${name} must have ${length} entries, not ${list.length}.`,\n );\n }\n }\n locales.set(code, data);\n}\n\nexport function hasLocale(code: LocaleCode): boolean {\n return locales.has(code);\n}\n\n/** The data for a locale, or English when the locale is not registered. */\nexport function localeData(code: LocaleCode): LocaleData {\n return locales.get(code) ?? en;\n}\n","import { NepDateRangeError } from './errors';\nimport { hasLocale } from './locale/registry';\nimport type { LocaleCode, Weekday } from './types';\n\n/**\n * Settings shared by both calendars. Calendar data is not here: the BS table is\n * managed by setBsData/patchBsYear, and AD needs no data (docs/plan D-001).\n */\nexport interface NepDateConfig {\n /** Which time zone decides \"today\" and the calendar day of an instant. */\n readonly timeZone: string;\n readonly weekStartsOn: Weekday;\n readonly weekendDays: readonly Weekday[];\n readonly defaultLocale: LocaleCode;\n}\n\nconst DEFAULTS: NepDateConfig = Object.freeze({\n timeZone: 'Asia/Kathmandu',\n weekStartsOn: 0,\n weekendDays: Object.freeze<Weekday[]>([6]),\n defaultLocale: 'en',\n});\n\nlet current: NepDateConfig = DEFAULTS;\n\n/** Change one or more settings. Every value is checked before any is applied. */\nexport function configure(changes: Partial<NepDateConfig>): void {\n const next = { ...current, ...changes };\n\n if (!isTimeZone(next.timeZone)) {\n throw new NepDateRangeError(\n 'INVALID_ARGUMENT',\n `\"${next.timeZone}\" is not a time zone.`,\n );\n }\n if (!isWeekday(next.weekStartsOn)) {\n throw new NepDateRangeError(\n 'INVALID_ARGUMENT',\n `weekStartsOn must be 0–6, not ${String(next.weekStartsOn)}.`,\n );\n }\n if (\n !next.weekendDays.every(isWeekday) ||\n new Set(next.weekendDays).size !== next.weekendDays.length\n ) {\n throw new NepDateRangeError(\n 'INVALID_ARGUMENT',\n 'weekendDays must be different weekdays, each 0–6.',\n );\n }\n if (!hasLocale(next.defaultLocale)) {\n throw new NepDateRangeError(\n 'INVALID_ARGUMENT',\n `Locale \"${next.defaultLocale}\" is not registered.`,\n );\n }\n\n current = Object.freeze({\n ...next,\n weekendDays: Object.freeze([...next.weekendDays]),\n });\n}\n\nexport function getConfig(): NepDateConfig {\n return current;\n}\n\n/** Back to the defaults (Kathmandu, Sunday first, Saturday weekend, English). */\nexport function resetConfig(): void {\n current = DEFAULTS;\n}\n\nexport function isWeekday(value: unknown): value is Weekday {\n return Number.isInteger(value) && (value as number) >= 0 && (value as number) <= 6;\n}\n\nfunction isTimeZone(value: string): boolean {\n try {\n new Intl.DateTimeFormat('en-US', { timeZone: value });\n\n return true;\n } catch {\n return false;\n }\n}\n","/**\n * The Gregorian (AD) calendar, by arithmetic only: no table, no BS knowledge,\n * no `Date`. Works for any year in ±MAX_AD_YEAR (docs/plan D-001).\n *\n * The day-count algorithms are Howard Hinnant's days_from_civil and\n * civil_from_days (proleptic Gregorian, March-based years).\n */\n\n/** AD years must lie within ±this value. */\nexport const MAX_AD_YEAR = 999_999;\n\nconst DAYS_BEFORE_EPOCH = 719_468; // 0000-03-01 → 1970-01-01\nconst DAYS_PER_ERA = 146_097; // 400 years\nconst MONTH_DAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\n\nexport function isAdLeapYear(year: number): boolean {\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n}\n\n/** Days in an AD month. The month must be 1–12. */\nexport function adMonthLength(year: number, month: number): number {\n return month === 2 && isAdLeapYear(year) ? 29 : (MONTH_DAYS[month - 1] ?? 0);\n}\n\nexport function isValidAdDate(year: number, month: number, day: number): boolean {\n return (\n Number.isInteger(year) &&\n Number.isInteger(month) &&\n Number.isInteger(day) &&\n Math.abs(year) <= MAX_AD_YEAR &&\n month >= 1 &&\n month <= 12 &&\n day >= 1 &&\n day <= adMonthLength(year, month)\n );\n}\n\n/** Days since 1970-01-01 of a valid AD date. */\nexport function adToEpoch(year: number, month: number, day: number): number {\n const y = month <= 2 ? year - 1 : year;\n const era = Math.floor(y / 400);\n const yearOfEra = y - era * 400;\n const dayOfYear = Math.floor((153 * (month + (month > 2 ? -3 : 9)) + 2) / 5) + day - 1;\n const dayOfEra =\n yearOfEra * 365 + Math.floor(yearOfEra / 4) - Math.floor(yearOfEra / 100) + dayOfYear;\n\n return era * DAYS_PER_ERA + dayOfEra - DAYS_BEFORE_EPOCH;\n}\n\n/** The AD year, month and day of a day count. */\nexport function epochToAd(epoch: number): { year: number; month: number; day: number } {\n const z = epoch + DAYS_BEFORE_EPOCH;\n const era = Math.floor(z / DAYS_PER_ERA);\n const dayOfEra = z - era * DAYS_PER_ERA;\n const yearOfEra = Math.floor(\n (dayOfEra -\n Math.floor(dayOfEra / 1460) +\n Math.floor(dayOfEra / 36_524) -\n Math.floor(dayOfEra / 146_096)) /\n 365,\n );\n const dayOfYear =\n dayOfEra -\n (365 * yearOfEra + Math.floor(yearOfEra / 4) - Math.floor(yearOfEra / 100));\n const shiftedMonth = Math.floor((5 * dayOfYear + 2) / 153);\n const day = dayOfYear - Math.floor((153 * shiftedMonth + 2) / 5) + 1;\n const month = shiftedMonth < 10 ? shiftedMonth + 3 : shiftedMonth - 9;\n const year = yearOfEra + era * 400 + (month <= 2 ? 1 : 0);\n\n return { year, month, day };\n}\n","/**\n * The Bikram Sambat calendar, from its table only. Nothing here reads or\n * produces an AD year: BS dates map to and from day counts (EpochDay) through\n * `epochStart` and the month lengths (docs/plan D-001).\n */\nimport { NepDateRangeError } from '../errors';\nimport type { BsData } from '../types';\nimport { BS_DATA } from './data/years';\n\ninterface BsTable {\n readonly data: BsData;\n readonly lastYear: number;\n /** yearStart[i] = day count of 1 Baisakh of firstYear + i; one extra entry for the end. */\n readonly yearStart: Float64Array;\n /** monthOffset[i * 12 + m] = days from 1 Baisakh to the first of month m + 1 in year i. */\n readonly monthOffset: Uint16Array;\n}\n\nlet data: BsData = freezeData(BS_DATA);\nlet table: BsTable | null = null;\n\n/** Replace the data the table is built from. Callers validate first (data-api.ts). */\nexport function useBsData(next: BsData): void {\n data = freezeData(next);\n table = null;\n}\n\nfunction freezeData(source: BsData): BsData {\n return Object.freeze({\n firstYear: source.firstYear,\n epochStart: source.epochStart,\n verifiedThrough: source.verifiedThrough,\n years: Object.freeze(source.years.map((months) => Object.freeze([...months]))),\n });\n}\n\nexport function currentBsData(): BsData {\n return data;\n}\n\nfunction buildTable(): BsTable {\n const count = data.years.length;\n const yearStart = new Float64Array(count + 1);\n const monthOffset = new Uint16Array(count * 12);\n let start = data.epochStart;\n\n for (let i = 0; i < count; i++) {\n yearStart[i] = start;\n const months = data.years[i] ?? [];\n let offset = 0;\n for (let m = 0; m < 12; m++) {\n monthOffset[i * 12 + m] = offset;\n offset += months[m] ?? 0;\n }\n start += offset;\n }\n yearStart[count] = start;\n\n return { data, lastYear: data.firstYear + count - 1, yearStart, monthOffset };\n}\n\nfunction bsTable(): BsTable {\n return (table ??= buildTable());\n}\n\nexport function bsFirstYear(): number {\n return data.firstYear;\n}\n\nexport function bsLastYear(): number {\n return bsTable().lastYear;\n}\n\n/** The first and last day counts the table covers. */\nexport function bsEpochRange(): { first: number; last: number } {\n const { yearStart } = bsTable();\n\n return { first: yearStart[0] ?? 0, last: (yearStart[yearStart.length - 1] ?? 0) - 1 };\n}\n\n/** Days in a BS month. Throws when the year is outside the table or the month is not 1–12. */\nexport function bsMonthLength(year: number, month: number): number {\n const { lastYear } = bsTable();\n if (!Number.isInteger(year) || year < data.firstYear || year > lastYear) {\n throw new NepDateRangeError(\n 'OUT_OF_TABLE',\n `BS year ${String(year)} is outside the supported range (BS ${data.firstYear}–${lastYear}).`,\n );\n }\n if (!Number.isInteger(month) || month < 1 || month > 12) {\n throw new NepDateRangeError(\n 'INVALID_DATE',\n `BS month ${String(month)} does not exist.`,\n );\n }\n\n return data.years[year - data.firstYear]?.[month - 1] ?? 0;\n}\n\nexport function isValidBsDate(year: number, month: number, day: number): boolean {\n try {\n return Number.isInteger(day) && day >= 1 && day <= bsMonthLength(year, month);\n } catch {\n return false;\n }\n}\n\n/** Day count of a valid BS date. */\nexport function bsToEpoch(year: number, month: number, day: number): number {\n const { yearStart, monthOffset } = bsTable();\n const index = year - data.firstYear;\n\n return (yearStart[index] ?? 0) + (monthOffset[index * 12 + month - 1] ?? 0) + day - 1;\n}\n\n/** The BS year, month and day of a day count. Throws when it is outside the table. */\nexport function epochToBs(epoch: number): { year: number; month: number; day: number } {\n const { yearStart, monthOffset } = bsTable();\n const { first, last } = bsEpochRange();\n if (epoch < first || epoch > last) {\n throw new NepDateRangeError(\n 'OUT_OF_TABLE',\n `Day ${epoch} is outside the BS table (BS ${data.firstYear}–${bsLastYear()}).`,\n );\n }\n\n // Last year whose start is on or before the day.\n let low = 0;\n let high = yearStart.length - 2;\n while (low < high) {\n const middle = Math.ceil((low + high) / 2);\n if ((yearStart[middle] ?? 0) <= epoch) {\n low = middle;\n } else {\n high = middle - 1;\n }\n }\n const dayOfYear = epoch - (yearStart[low] ?? 0);\n let month = 11;\n while (month > 0 && (monthOffset[low * 12 + month] ?? 0) > dayOfYear) {\n month--;\n }\n\n return {\n year: data.firstYear + low,\n month: month + 1,\n day: dayOfYear - (monthOffset[low * 12 + month] ?? 0) + 1,\n };\n}\n\n/** Whether a BS year is after the last year checked against a published calendar. */\nexport function isProjectedBsYear(year: number): boolean {\n return year > data.verifiedThrough;\n}\n","import { NepDateDataError, NepDateRangeError } from '../errors';\nimport type { BsData } from '../types';\nimport { BS_DATA } from './data/years';\nimport { currentBsData, useBsData } from './table';\n\n/** The first BS month of Nepal's fiscal year: Shrawan. */\nexport const BS_FISCAL_YEAR_START_MONTH = 4;\n\n/** Days a verified year may have. Projected years may be off by one (the bundled BS 2096 lists 364). */\nconst VERIFIED_YEAR_DAYS = [365, 366];\nconst PROJECTED_YEAR_DAYS = [364, 365, 366, 367];\n\n/** Throws NepDateDataError when the table is not usable. Same rules as scripts/gen-data.ts. */\nexport function validateBsData(table: BsData): void {\n if (!Number.isSafeInteger(table.epochStart) || !Number.isInteger(table.firstYear)) {\n throw new NepDateDataError(\n 'BAD_ANCHOR',\n 'firstYear and epochStart must be whole numbers.',\n );\n }\n if (!Number.isInteger(table.verifiedThrough)) {\n throw new NepDateDataError('BAD_ANCHOR', 'verifiedThrough must be a whole number.');\n }\n if (table.years.length === 0) {\n throw new NepDateDataError('EMPTY', 'The BS table has no years.');\n }\n\n table.years.forEach((months, index) => {\n const year = table.firstYear + index;\n if (months.length !== 12) {\n throw new NepDateDataError(\n 'BAD_MONTH_COUNT',\n `BS ${year} lists ${months.length} months, not 12.`,\n year,\n );\n }\n let total = 0;\n months.forEach((days, m) => {\n if (!Number.isInteger(days) || days < 29 || days > 32) {\n throw new NepDateDataError(\n 'BAD_MONTH',\n `BS ${year} month ${m + 1} has ${String(days)} days; expected 29–32.`,\n year,\n m + 1,\n );\n }\n total += days;\n });\n const allowed =\n year <= table.verifiedThrough ? VERIFIED_YEAR_DAYS : PROJECTED_YEAR_DAYS;\n if (!allowed.includes(total)) {\n throw new NepDateDataError(\n 'BAD_YEAR_TOTAL',\n `BS ${year} has ${total} days; expected ${allowed.join(' or ')}.`,\n year,\n );\n }\n });\n}\n\n/** The BS table in use (frozen). */\nexport function getBsData(): BsData {\n return currentBsData();\n}\n\n/** Replace the whole BS table. Only BS results change; AD functions are unaffected. */\nexport function setBsData(table: BsData): void {\n validateBsData(table);\n useBsData(table);\n}\n\n/**\n * Correct one year's month lengths, or add the year just before the first or\n * just after the last. Years after a corrected year move with it; earlier years\n * never move (adding a year before the first keeps every existing year in place).\n */\nexport function patchBsYear(year: number, months: readonly number[]): void {\n const table = currentBsData();\n const lastYear = table.firstYear + table.years.length - 1;\n let next: BsData;\n\n if (year >= table.firstYear && year <= lastYear) {\n next = {\n ...table,\n years: table.years.map((row, index) =>\n index === year - table.firstYear ? months : row,\n ),\n };\n } else if (year === lastYear + 1) {\n next = { ...table, years: [...table.years, months] };\n } else if (year === table.firstYear - 1) {\n const length = months.reduce((total, days) => total + days, 0);\n next = {\n ...table,\n firstYear: year,\n epochStart: table.epochStart - length,\n years: [months, ...table.years],\n };\n } else {\n throw new NepDateRangeError(\n 'OUT_OF_TABLE',\n `BS ${String(year)} is not in the table and does not extend it (BS ${table.firstYear}–${lastYear}).`,\n );\n }\n\n setBsData(next);\n}\n\n/** Back to the table bundled with the package. */\nexport function resetBsData(): void {\n useBsData(BS_DATA);\n}\n","import { adMonthLength, isValidAdDate, MAX_AD_YEAR } from './ad/calendar';\nimport { bsMonthLength, isValidBsDate } from './bs/table';\nimport { NepDateRangeError } from './errors';\nimport type {\n AdDate,\n BsDate,\n CalendarDate,\n CalendarSystem,\n DateOf,\n MonthNumber,\n} from './types';\n\n/** An AD date. Any year within ±999,999 is allowed; only conversion to BS is limited. */\nexport function adDate(year: number, month: number, day: number): AdDate {\n if (!isValidAdDate(year, month, day)) {\n throw new NepDateRangeError(\n Number.isInteger(year) && Number.isInteger(month) && Number.isInteger(day)\n ? 'INVALID_DATE'\n : 'INVALID_ARGUMENT',\n Math.abs(year) > MAX_AD_YEAR\n ? `AD year ${String(year)} is outside ±${MAX_AD_YEAR}.`\n : `AD ${String(year)}-${String(month)}-${String(day)} is not a valid date.`,\n );\n }\n\n return Object.freeze({ calendar: 'AD', year, month: month as MonthNumber, day });\n}\n\n/** A BS date. The year must be in the BS table. */\nexport function bsDate(year: number, month: number, day: number): BsDate {\n const length = bsMonthLength(year, month);\n if (!Number.isInteger(day) || day < 1 || day > length) {\n throw new NepDateRangeError(\n Number.isInteger(day) ? 'INVALID_DATE' : 'INVALID_ARGUMENT',\n `BS ${year}-${month} has ${length} days, not ${String(day)}.`,\n );\n }\n\n return Object.freeze({ calendar: 'BS', year, month: month as MonthNumber, day });\n}\n\nexport function createDate<C extends CalendarSystem>(\n calendar: C,\n year: number,\n month: number,\n day: number,\n): DateOf<C> {\n return (\n calendar === 'AD' ? adDate(year, month, day) : bsDate(year, month, day)\n ) as DateOf<C>;\n}\n\nexport function isValidDate(\n calendar: CalendarSystem,\n year: number,\n month: number,\n day: number,\n): boolean {\n return calendar === 'AD'\n ? isValidAdDate(year, month, day)\n : isValidBsDate(year, month, day);\n}\n\n/** Days in a month of either calendar. */\nexport function daysInMonth(\n calendar: CalendarSystem,\n year: number,\n month: number,\n): number {\n if (calendar === 'BS') {\n return bsMonthLength(year, month);\n }\n if (!isValidAdDate(year, month, 1)) {\n throw new NepDateRangeError(\n 'INVALID_DATE',\n `AD ${String(year)}-${String(month)} is not a month.`,\n );\n }\n\n return adMonthLength(year, month);\n}\n\n/** True for a valid, frozen-or-not AD date object (e.g. from JSON). */\nexport function isAdDate(value: unknown): value is AdDate {\n return isDateLike(value, 'AD') && isValidAdDate(value.year, value.month, value.day);\n}\n\n/** True for a valid BS date object (e.g. from JSON). */\nexport function isBsDate(value: unknown): value is BsDate {\n return isDateLike(value, 'BS') && isValidBsDate(value.year, value.month, value.day);\n}\n\nexport function isCalendarDate(value: unknown): value is CalendarDate {\n return isAdDate(value) || isBsDate(value);\n}\n\nfunction isDateLike(\n value: unknown,\n calendar: CalendarSystem,\n): value is { calendar: CalendarSystem; year: number; month: number; day: number } {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n const record = value as Record<string, unknown>;\n\n return (\n record['calendar'] === calendar &&\n typeof record['year'] === 'number' &&\n typeof record['month'] === 'number' &&\n typeof record['day'] === 'number'\n );\n}\n","/**\n * The only place the AD and BS calendars meet, and only through EpochDay\n * (docs/plan D-001). Nothing here looks up a year number across calendars.\n */\nimport { adToEpoch, epochToAd } from './ad/calendar';\nimport { bsEpochRange, bsToEpoch, epochToBs } from './bs/table';\nimport { getConfig } from './config';\nimport { adDate, bsDate } from './create';\nimport { toEpochDay } from './epoch';\nimport { NepDateRangeError } from './errors';\nimport type {\n AdDate,\n BsDate,\n CalendarDate,\n CalendarSystem,\n DateOf,\n EpochDay,\n} from './types';\n\n/** The day count of a date in either calendar. */\nexport function toEpoch(date: CalendarDate): EpochDay {\n return toEpochDay(\n date.calendar === 'AD'\n ? adToEpoch(date.year, date.month, date.day)\n : bsToEpoch(date.year, date.month, date.day),\n );\n}\n\n/** The date of a day count in a calendar. BS throws OUT_OF_TABLE outside the table. */\nexport function fromEpoch<C extends CalendarSystem>(\n epoch: EpochDay,\n calendar: C,\n): DateOf<C> {\n if (calendar === 'AD') {\n const { year, month, day } = epochToAd(epoch);\n\n return adDate(year, month, day) as DateOf<C>;\n }\n assertConvertible(epoch);\n const { year, month, day } = epochToBs(epoch);\n\n return bsDate(year, month, day) as DateOf<C>;\n}\n\nexport function adToBs(date: AdDate): BsDate {\n return fromEpoch(toEpoch(date), 'BS');\n}\n\nexport function bsToAd(date: BsDate): AdDate {\n return fromEpoch(toEpoch(date), 'AD');\n}\n\n/** The same day in the given calendar (the date itself when it is already in it). */\nexport function toCalendar<C extends CalendarSystem>(\n date: CalendarDate,\n calendar: C,\n): DateOf<C> {\n if (date.calendar === calendar) {\n return date as DateOf<C>;\n }\n\n return fromEpoch(toEpoch(date), calendar);\n}\n\n/** The first day that can be converted, in either calendar (the start of the BS table). */\nexport function minDate<C extends CalendarSystem>(calendar: C): DateOf<C> {\n return fromEpoch(toEpochDay(bsEpochRange().first), calendar);\n}\n\n/** The last day that can be converted, in either calendar (the end of the BS table). */\nexport function maxDate<C extends CalendarSystem>(calendar: C): DateOf<C> {\n return fromEpoch(toEpochDay(bsEpochRange().last), calendar);\n}\n\n/** Whether a date can be converted to the other calendar. */\nexport function isConvertible(date: CalendarDate): boolean {\n const epoch = toEpoch(date);\n const { first, last } = bsEpochRange();\n\n return epoch >= first && epoch <= last;\n}\n\n/** The AD day as \"YYYY-MM-DD\", the form to store and send (docs/plan D-003). */\nexport function toIsoDate(date: CalendarDate): string {\n const { year, month, day } = toCalendar(date, 'AD');\n if (year < 0 || year > 9999) {\n throw new NepDateRangeError(\n 'INVALID_ARGUMENT',\n `AD year ${year} cannot be written as YYYY-MM-DD.`,\n );\n }\n\n return `${pad(year, 4)}-${pad(month, 2)}-${pad(day, 2)}`;\n}\n\n/**\n * An AD date from \"YYYY-MM-DD\", or from a longer ISO timestamp by its date part\n * (\"2026-10-18T09:30:00Z\" → 2026-10-18). Null for anything else.\n */\nexport function fromIsoDate(value: string | null | undefined): AdDate | null {\n const match = /^(\\d{4})-(\\d{2})-(\\d{2})(?:$|[T ])/.exec(value ?? '');\n if (!match) {\n return null;\n }\n try {\n return adDate(Number(match[1]), Number(match[2]), Number(match[3]));\n } catch {\n return null;\n }\n}\n\n/** The AD calendar day an instant falls on in a time zone (Nepal by default). */\nexport function fromJsDate(\n instant: Date,\n timeZone: string = getConfig().timeZone,\n): AdDate {\n if (Number.isNaN(instant.getTime())) {\n throw new NepDateRangeError('INVALID_ARGUMENT', 'The Date is invalid.');\n }\n let parts: Intl.DateTimeFormatPart[];\n try {\n parts = new Intl.DateTimeFormat('en-US', {\n timeZone,\n year: 'numeric',\n month: 'numeric',\n day: 'numeric',\n era: 'short',\n }).formatToParts(instant);\n } catch {\n throw new NepDateRangeError('INVALID_ARGUMENT', `\"${timeZone}\" is not a time zone.`);\n }\n const part = (type: Intl.DateTimeFormatPartTypes): string =>\n parts.find((item) => item.type === type)?.value ?? '';\n const year = Number(part('year'));\n\n return adDate(\n part('era') === 'BC' ? 1 - year : year,\n Number(part('month')),\n Number(part('day')),\n );\n}\n\n/**\n * The calendar day and time of an ISO timestamp *with a zone* (\"…Z\",\n * \"…+05:45\"), read in `timeZone` (Nepal by default). Null for anything else,\n * including plain dates, which have no instant.\n */\nexport function fromIsoTimestamp(\n value: string | null | undefined,\n timeZone: string = getConfig().timeZone,\n): { readonly date: AdDate; readonly time: string } | null {\n if (!value || !/T.*(?:Z|[+-]\\d{2}:?\\d{2})$/.test(value)) {\n return null;\n }\n const instant = new Date(value);\n if (Number.isNaN(instant.getTime())) {\n return null;\n }\n const time = new Intl.DateTimeFormat('en-GB', {\n timeZone,\n hour: '2-digit',\n minute: '2-digit',\n hourCycle: 'h23',\n }).format(instant);\n\n return { date: fromJsDate(instant, timeZone), time };\n}\n\nfunction assertConvertible(epoch: number): void {\n const { first, last } = bsEpochRange();\n if (epoch < first || epoch > last) {\n const { year, month, day } = epochToAd(epoch);\n const from = epochToAd(first);\n const to = epochToAd(last);\n throw new NepDateRangeError(\n 'OUT_OF_TABLE',\n `AD ${isoParts(year, month, day)} is outside the BS table (AD ${isoParts(from.year, from.month, from.day)} to ${isoParts(to.year, to.month, to.day)}).`,\n );\n }\n}\n\nfunction isoParts(year: number, month: number, day: number): string {\n return `${year}-${pad(month, 2)}-${pad(day, 2)}`;\n}\n\nfunction pad(value: number, length: number): string {\n return String(value).padStart(length, '0');\n}\n","import { isProjectedBsYear } from './bs/table';\nimport { toCalendar } from './convert';\nimport type { CalendarDate } from './types';\n\n/** Whether the date's BS year is after the last year checked against a published calendar. */\nexport function isProjected(date: CalendarDate): boolean {\n return isProjectedBsYear(toCalendar(date, 'BS').year);\n}\n","import { getConfig } from './config';\nimport { fromIsoTimestamp, fromJsDate, toCalendar } from './convert';\nimport type { AdDate, CalendarSystem, DateOf } from './types';\n\n/**\n * Today's date by the calendar day in `timeZone` (Nepal by default), not the\n * device's zone. The only function in the library that reads the clock.\n */\nexport function today(): AdDate;\nexport function today<C extends CalendarSystem>(\n calendar: C,\n timeZone?: string,\n): DateOf<C>;\nexport function today(\n calendar: CalendarSystem = 'AD',\n timeZone: string = getConfig().timeZone,\n): AdDate | DateOf<CalendarSystem> {\n return toCalendar(fromJsDate(new Date(), timeZone), calendar);\n}\n\n/** The current calendar day and time (HH:MM) in `timeZone` (Nepal by default). */\nexport function now(timeZone: string = getConfig().timeZone): {\n readonly date: AdDate;\n readonly time: { readonly hour: number; readonly minute: number };\n} {\n const current = fromIsoTimestamp(new Date().toISOString(), timeZone);\n const [hour = 0, minute = 0] = (current?.time ?? '00:00').split(':').map(Number);\n\n return {\n date: current?.date ?? fromJsDate(new Date(), timeZone),\n time: Object.freeze({ hour, minute }),\n };\n}\n","import { getConfig, isWeekday } from './config';\nimport { fromEpoch, toCalendar, toEpoch } from './convert';\nimport { createDate, daysInMonth } from './create';\nimport { toEpochDay, weekdayOf } from './epoch';\nimport { NepDateRangeError } from './errors';\nimport type { CalendarDate, DateOf, Weekday } from './types';\n\n/** A date in the same calendar as `D`. */\ntype Same<D extends CalendarDate> = DateOf<D['calendar']>;\n\nexport function addDays<D extends CalendarDate>(date: D, days: number): Same<D> {\n assertInteger(days, 'days');\n\n return fromEpoch(toEpochDay(toEpoch(date) + days), date.calendar) as Same<D>;\n}\n\n/** Move by whole months in the date's own calendar; the day is capped to the new month's length. */\nexport function addMonths<D extends CalendarDate>(date: D, months: number): Same<D> {\n assertInteger(months, 'months');\n const index = date.year * 12 + (date.month - 1) + months;\n const year = Math.floor(index / 12);\n const month = index - year * 12 + 1;\n const day = Math.min(date.day, daysInMonth(date.calendar, year, month));\n\n return createDate(date.calendar, year, month, day) as Same<D>;\n}\n\n/** Move by whole years in the date's own calendar; the day is capped (29 Feb, short BS months). */\nexport function addYears<D extends CalendarDate>(date: D, years: number): Same<D> {\n assertInteger(years, 'years');\n\n return addMonths(date, years * 12);\n}\n\nexport function startOfMonth<D extends CalendarDate>(date: D): Same<D> {\n return createDate(date.calendar, date.year, date.month, 1) as Same<D>;\n}\n\nexport function endOfMonth<D extends CalendarDate>(date: D): Same<D> {\n return createDate(\n date.calendar,\n date.year,\n date.month,\n daysInMonth(date.calendar, date.year, date.month),\n ) as Same<D>;\n}\n\nexport function startOfYear<D extends CalendarDate>(date: D): Same<D> {\n return createDate(date.calendar, date.year, 1, 1) as Same<D>;\n}\n\nexport function endOfYear<D extends CalendarDate>(date: D): Same<D> {\n return createDate(\n date.calendar,\n date.year,\n 12,\n daysInMonth(date.calendar, date.year, 12),\n ) as Same<D>;\n}\n\nexport function startOfWeek<D extends CalendarDate>(\n date: D,\n weekStartsOn: Weekday = getConfig().weekStartsOn,\n): Same<D> {\n assertWeekday(weekStartsOn);\n const back = (weekdayOf(toEpoch(date)) - weekStartsOn + 7) % 7;\n\n return addDays(date, -back);\n}\n\nexport function endOfWeek<D extends CalendarDate>(\n date: D,\n weekStartsOn: Weekday = getConfig().weekStartsOn,\n): Same<D> {\n return addDays(startOfWeek(date, weekStartsOn), 6);\n}\n\n/** Whole days from `b` to `a` (positive when `a` is later). The calendars may differ. */\nexport function differenceInDays(a: CalendarDate, b: CalendarDate): number {\n return toEpoch(a) - toEpoch(b);\n}\n\n/** Every day from `start` to `end` inclusive, in `start`'s calendar. Nothing when end < start. */\nexport function* eachDayOfInterval<D extends CalendarDate>(\n start: D,\n end: CalendarDate,\n): Generator<Same<D>, void, undefined> {\n const last = toEpoch(end);\n for (let epoch = toEpoch(start); epoch <= last; epoch++) {\n yield fromEpoch(toEpochDay(epoch), start.calendar) as Same<D>;\n }\n}\n\n/** Every day of the month the date is in. */\nexport function eachDayOfMonth<D extends CalendarDate>(date: D): Same<D>[] {\n return [...eachDayOfInterval(startOfMonth(date), endOfMonth(date))] as Same<D>[];\n}\n\n/** The date converted to `target`'s calendar; a small helper used by compare and fiscal code. */\nexport function inCalendarOf<D extends CalendarDate>(\n target: D,\n date: CalendarDate,\n): Same<D> {\n return toCalendar(date, target.calendar) as Same<D>;\n}\n\nfunction assertInteger(value: number, name: string): void {\n if (!Number.isSafeInteger(value)) {\n throw new NepDateRangeError(\n 'INVALID_ARGUMENT',\n `${name} must be a whole number, not ${String(value)}.`,\n );\n }\n}\n\nfunction assertWeekday(value: number): void {\n if (!isWeekday(value)) {\n throw new NepDateRangeError(\n 'INVALID_ARGUMENT',\n `${String(value)} is not a weekday (0–6).`,\n );\n }\n}\n","import { inCalendarOf } from './arithmetic';\nimport { getConfig } from './config';\nimport { toCalendar, toEpoch } from './convert';\nimport { weekdayOf } from './epoch';\nimport type { CalendarDate, DateOf, Weekday } from './types';\n\ntype Maybe = CalendarDate | null | undefined;\n\n/** -1, 0 or 1. Dates in different calendars compare by the day they fall on. */\nexport function compareDates(a: CalendarDate, b: CalendarDate): -1 | 0 | 1 {\n return Math.sign(toEpoch(a) - toEpoch(b)) as -1 | 0 | 1;\n}\n\n/** Same day, in any calendars. False when either is missing. */\nexport function isSameDay(a: Maybe, b: Maybe): boolean {\n return a != null && b != null && toEpoch(a) === toEpoch(b);\n}\n\n/** Whether `b` falls in the same month as `a`, judged in `a`'s calendar. */\nexport function isSameMonth(a: CalendarDate, b: CalendarDate): boolean {\n const other = inCalendarOf(a, b);\n\n return other.year === a.year && other.month === a.month;\n}\n\n/** Whether `b` falls in the same year as `a`, judged in `a`'s calendar. */\nexport function isSameYear(a: CalendarDate, b: CalendarDate): boolean {\n return inCalendarOf(a, b).year === a.year;\n}\n\nexport function isBefore(a: CalendarDate, b: CalendarDate): boolean {\n return toEpoch(a) < toEpoch(b);\n}\n\nexport function isAfter(a: CalendarDate, b: CalendarDate): boolean {\n return toEpoch(a) > toEpoch(b);\n}\n\n/** On or after `min` and on or before `max`; a missing bound is open. */\nexport function isWithin(date: CalendarDate, min?: Maybe, max?: Maybe): boolean {\n const day = toEpoch(date);\n\n return (min == null || day >= toEpoch(min)) && (max == null || day <= toEpoch(max));\n}\n\n/** The date, or the nearest bound when it is outside, in the date's calendar. */\nexport function clampDate<D extends CalendarDate>(\n date: D,\n min?: Maybe,\n max?: Maybe,\n): DateOf<D['calendar']> {\n if (min != null && isBefore(date, min)) {\n return toCalendar(min, date.calendar) as DateOf<D['calendar']>;\n }\n if (max != null && isAfter(date, max)) {\n return toCalendar(max, date.calendar) as DateOf<D['calendar']>;\n }\n\n return date as DateOf<D['calendar']>;\n}\n\n/** 0 = Sunday … 6 = Saturday. The same in both calendars. */\nexport function dayOfWeek(date: CalendarDate): Weekday {\n return weekdayOf(toEpoch(date));\n}\n\n/** Saturday by default (Nepal); set `weekendDays` in configure() or pass them here. */\nexport function isWeekend(\n date: CalendarDate,\n weekendDays: readonly Weekday[] = getConfig().weekendDays,\n): boolean {\n return weekendDays.includes(dayOfWeek(date));\n}\n","import { getConfig } from '../config';\nimport type { CalendarSystem, LocaleCode } from '../types';\nimport { localeData, type LocaleData } from './registry';\n\nexport { hasLocale, registerLocale, type LocaleData } from './registry';\n\nconst DEVANAGARI = ['०', '१', '२', '३', '४', '५', '६', '७', '८', '९'];\n\n/** The data for a locale (the configured default when omitted; English when unknown). */\nexport function getLocale(locale: LocaleCode = getConfig().defaultLocale): LocaleData {\n return localeData(locale);\n}\n\nexport function monthNames(\n calendar: CalendarSystem,\n locale?: LocaleCode,\n width: 'long' | 'short' = 'long',\n): readonly string[] {\n return getLocale(locale).months[calendar][width];\n}\n\nexport function weekdayNames(\n locale?: LocaleCode,\n width: 'long' | 'short' | 'narrow' = 'long',\n): readonly string[] {\n return getLocale(locale).weekdays[width];\n}\n\n/** Replace Devanagari digits with ASCII digits. */\nexport function toAsciiDigits(value: string): string {\n return value.replace(/[०-९]/g, (digit) => String(DEVANAGARI.indexOf(digit)));\n}\n\n/** Replace ASCII digits with Devanagari digits. */\nexport function toDevanagariDigits(value: string | number): string {\n return String(value).replace(/[0-9]/g, (digit) => DEVANAGARI[Number(digit)] ?? digit);\n}\n\n/** Write a number (or digit string) with the locale's digits. */\nexport function formatNumber(value: string | number, locale?: LocaleCode): string {\n const { digits } = getLocale(locale);\n\n return String(value).replace(/[0-9]/g, (digit) => digits[Number(digit)] ?? digit);\n}\n\n/** Fill {name} placeholders in a locale message. */\nexport function formatMessage(template: string, values: Record<string, string>): string {\n return template.replace(/\\{(\\w+)\\}/g, (whole, name: string) => values[name] ?? whole);\n}\n","import { dayOfWeek } from './compare';\nimport { formatNumber, getLocale } from './locale/index';\nimport type { CalendarDate, LocaleCode } from './types';\n\n/** Named formats. `cbms` is the dotted form Nepal's tax system uses. */\nexport const DATE_FORMATS: {\n readonly iso: 'Y-m-d';\n readonly cbms: 'Y.m.d';\n readonly short: 'j M Y';\n readonly long: 'j F Y';\n readonly full: 'l, j F Y';\n} = Object.freeze({\n iso: 'Y-m-d',\n cbms: 'Y.m.d',\n short: 'j M Y',\n long: 'j F Y',\n full: 'l, j F Y',\n});\n\nexport type NamedFormat = keyof typeof DATE_FORMATS;\n/** A named format, or a pattern of tokens (see formatDate). */\nexport type DateFormatPattern = NamedFormat | (string & Record<never, never>);\n\n/**\n * Format a date in its own calendar. Tokens: Y 2083, y 83, m 06, n 6, d 09,\n * j 9, F month name, M short month name, l weekday, D short weekday. Put a\n * backslash before a letter to print it as is. Digits follow the locale.\n *\n * formatDate(bsDate(2082, 4, 1), 'full') → \"Thursday, 1 Shrawan 2082\"\n * formatDate(bsDate(2082, 4, 1), 'long', 'ne') → \"१ साउन २०८२\"\n */\nexport function formatDate(\n date: CalendarDate,\n pattern: DateFormatPattern = 'iso',\n locale?: LocaleCode,\n): string {\n const tokens: string =\n pattern in DATE_FORMATS ? DATE_FORMATS[pattern as NamedFormat] : pattern;\n const data = getLocale(locale);\n const months = data.months[date.calendar];\n const digits = (value: string | number): string => formatNumber(value, locale);\n const pad = (value: number): string => String(value).padStart(2, '0');\n let output = '';\n\n for (let index = 0; index < tokens.length; index++) {\n const token = tokens.charAt(index);\n switch (token) {\n case '\\\\':\n index++;\n output += tokens.charAt(index);\n break;\n case 'Y':\n output += digits(date.year);\n break;\n case 'y':\n output += digits(pad(((date.year % 100) + 100) % 100));\n break;\n case 'm':\n output += digits(pad(date.month));\n break;\n case 'n':\n output += digits(date.month);\n break;\n case 'd':\n output += digits(pad(date.day));\n break;\n case 'j':\n output += digits(date.day);\n break;\n case 'F':\n output += months.long[date.month - 1] ?? '';\n break;\n case 'M':\n output += months.short[date.month - 1] ?? '';\n break;\n case 'l':\n output += data.weekdays.long[dayOfWeek(date)] ?? '';\n break;\n case 'D':\n output += data.weekdays.short[dayOfWeek(date)] ?? '';\n break;\n default:\n output += token;\n }\n }\n\n return output;\n}\n","import { BS_FISCAL_YEAR_START_MONTH } from './bs/data-api';\nimport { compareDates } from './compare';\nimport { toCalendar } from './convert';\nimport { bsDate, daysInMonth } from './create';\nimport { formatNumber } from './locale/index';\nimport type { CalendarDate, FiscalYear, LocaleCode } from './types';\n\n/** The fiscal year a date falls in: 1 Shrawan to the end of Asar. */\nexport function fiscalYear(date: CalendarDate): FiscalYear {\n const bs = toCalendar(date, 'BS');\n\n return fiscalYearRange(bs.month >= BS_FISCAL_YEAR_START_MONTH ? bs.year : bs.year - 1);\n}\n\n/** The fiscal year that starts in BS `startYear` (2083 → FY 2083/84). */\nexport function fiscalYearRange(startYear: number): FiscalYear {\n const endYear = startYear + 1;\n const lastMonth = BS_FISCAL_YEAR_START_MONTH - 1;\n\n return Object.freeze({\n startYear,\n label: `${startYear}/${String(endYear % 100).padStart(2, '0')}`,\n firstDay: bsDate(startYear, BS_FISCAL_YEAR_START_MONTH, 1),\n lastDay: bsDate(endYear, lastMonth, daysInMonth('BS', endYear, lastMonth)),\n });\n}\n\n/**\n * label \"2083/84\" · full \"2083/2084\" · cbms \"2083.084\" (the form Nepal's tax\n * system uses). Digits follow the locale.\n */\nexport function formatFiscalYear(\n fy: FiscalYear,\n style: 'label' | 'full' | 'cbms' = 'label',\n locale?: LocaleCode,\n): string {\n const end = fy.startYear + 1;\n const text =\n style === 'full'\n ? `${fy.startYear}/${end}`\n : style === 'cbms'\n ? `${fy.startYear}.${String(end % 1000).padStart(3, '0')}`\n : fy.label;\n\n return formatNumber(text, locale);\n}\n\nexport function isInFiscalYear(date: CalendarDate, fy: FiscalYear): boolean {\n return compareDates(date, fy.firstDay) >= 0 && compareDates(date, fy.lastDay) <= 0;\n}\n","import { createDate } from './create';\nimport { NepDateRangeError } from './errors';\nimport { fiscalYearRange } from './fiscal';\nimport { toAsciiDigits } from './locale/index';\nimport type { CalendarSystem, DateOf, FiscalYear } from './types';\n\nconst YEAR_FIRST = /^(\\d{4})[-./](\\d{1,2})[-./](\\d{1,2})$/;\nconst COMPACT = /^(\\d{4})(\\d{2})(\\d{2})$/;\n\n/**\n * A date written year first (\"2083-06-24\", \"2083/6/24\", \"2083.06.24\", or\n * compact \"20830624\") in ASCII or Devanagari digits, in the calendar the caller names. Other orders are\n * rejected, not guessed. Returns null when the text is not a valid date.\n */\nexport function parseDate<C extends CalendarSystem>(\n text: string | null | undefined,\n calendar: C,\n): DateOf<C> | null {\n try {\n return parseDateStrict(text ?? '', calendar);\n } catch {\n return null;\n }\n}\n\n/** Like parseDate, but throws a NepDateRangeError that says what is wrong. */\nexport function parseDateStrict<C extends CalendarSystem>(\n text: string,\n calendar: C,\n): DateOf<C> {\n const ascii = toAsciiDigits(text).trim();\n const match = YEAR_FIRST.exec(ascii) ?? COMPACT.exec(ascii);\n if (!match) {\n throw new NepDateRangeError(\n 'INVALID_ARGUMENT',\n `\"${text}\" is not a date written as YYYY-MM-DD.`,\n );\n }\n\n return createDate(calendar, Number(match[1]), Number(match[2]), Number(match[3]));\n}\n\n/**\n * A fiscal year from its label: \"2083/84\", \"2083/2084\", \"2083-84\" or the\n * tax form \"2083.084\", in ASCII or Devanagari digits. Null when not valid.\n */\nexport function parseFiscalYear(text: string | null | undefined): FiscalYear | null {\n const match = /^(\\d{4})\\s*[-/.]\\s*(\\d{2,4})$/.exec(toAsciiDigits(text ?? '').trim());\n if (!match) {\n return null;\n }\n const start = Number(match[1]);\n const end = match[2] ?? '';\n const next = start + 1;\n const expected =\n end.length === 4\n ? String(next)\n : String(next % 10 ** end.length).padStart(end.length, '0');\n if (end !== expected) {\n return null;\n }\n try {\n return fiscalYearRange(start);\n } catch {\n return null;\n }\n}\n","import { getConfig } from './config';\nimport { fromIsoTimestamp, toCalendar } from './convert';\nimport { adDate } from './create';\nimport { NepDateRangeError } from './errors';\nimport { formatNumber, getLocale, toAsciiDigits } from './locale/index';\nimport type { AdDate, CalendarDate, LocaleCode } from './types';\n\n/** A time of day, 00:00–23:59. Frozen like dates. */\nexport interface TimeOfDay {\n readonly hour: number;\n readonly minute: number;\n}\n\nexport function timeOfDay(hour: number, minute = 0): TimeOfDay {\n if (!isValidTime(hour, minute)) {\n throw new NepDateRangeError(\n 'INVALID_ARGUMENT',\n `${String(hour)}:${String(minute)} is not a time of day.`,\n );\n }\n\n return Object.freeze({ hour, minute });\n}\n\nexport function isValidTime(hour: number, minute: number): boolean {\n return (\n Number.isInteger(hour) &&\n Number.isInteger(minute) &&\n hour >= 0 &&\n hour <= 23 &&\n minute >= 0 &&\n minute <= 59\n );\n}\n\n/** -1, 0 or 1. */\nexport function compareTimes(a: TimeOfDay, b: TimeOfDay): -1 | 0 | 1 {\n return Math.sign(a.hour * 60 + a.minute - (b.hour * 60 + b.minute)) as -1 | 0 | 1;\n}\n\n/**\n * \"14:30\", \"2:30 pm\", \"2 PM\", \"1430\", \"१४:३०\", \"२:३० अपराह्न\" → TimeOfDay.\n * Null when the text is not a time.\n */\nexport function parseTime(text: string | null | undefined): TimeOfDay | null {\n let value = toAsciiDigits(text ?? '')\n .trim()\n .toLowerCase();\n let meridiem: 'am' | 'pm' | null = null;\n for (const code of ['en', 'ne'] as const) {\n const { am, pm } = getLocale(code).time;\n for (const [word, kind] of [\n [am.toLowerCase(), 'am'],\n [pm.toLowerCase(), 'pm'],\n [am.toLowerCase().replace(/(.)/g, '$1.'), 'am'],\n [pm.toLowerCase().replace(/(.)/g, '$1.'), 'pm'],\n ] as const) {\n if (value.endsWith(word)) {\n meridiem = kind;\n value = value.slice(0, -word.length).trim();\n break;\n }\n }\n if (meridiem) {\n break;\n }\n }\n const match =\n /^(\\d{1,2})(?:[:.](\\d{2}))?$/.exec(value) ?? /^(\\d{2})(\\d{2})$/.exec(value);\n if (!match) {\n return null;\n }\n let hour = Number(match[1]);\n const minute = Number(match[2] ?? 0);\n if (meridiem) {\n if (hour < 1 || hour > 12) {\n return null;\n }\n hour = (hour % 12) + (meridiem === 'pm' ? 12 : 0);\n }\n\n return isValidTime(hour, minute) ? timeOfDay(hour, minute) : null;\n}\n\n/** \"14:30\" (24-hour) or \"2:30 PM\" (hour12), in the locale's digits and words. */\nexport function formatTime(\n time: TimeOfDay,\n options: { readonly hour12?: boolean; readonly locale?: LocaleCode } = {},\n): string {\n const minute = String(time.minute).padStart(2, '0');\n if (!options.hour12) {\n return formatNumber(\n `${String(time.hour).padStart(2, '0')}:${minute}`,\n options.locale,\n );\n }\n const { am, pm } = getLocale(options.locale).time;\n const hour = time.hour % 12 === 0 ? 12 : time.hour % 12;\n\n return `${formatNumber(`${hour}:${minute}`, options.locale)} ${time.hour < 12 ? am : pm}`;\n}\n\n/**\n * The instant of a calendar day and time in a zone (Nepal by default), as an\n * ISO timestamp with that zone's offset: \"2026-10-18T14:30:00+05:45\".\n */\nexport function toIsoDateTime(\n date: CalendarDate,\n time: TimeOfDay,\n timeZone: string = getConfig().timeZone,\n): string {\n const { year, month, day } = toCalendar(date, 'AD');\n if (year < 0 || year > 9999) {\n throw new NepDateRangeError(\n 'INVALID_ARGUMENT',\n `AD year ${year} cannot be written in ISO form.`,\n );\n }\n const wall = Date.UTC(year, month - 1, day, time.hour, time.minute);\n const first = offsetMinutes(wall, timeZone);\n const offset = offsetMinutes(wall - first * 60_000, timeZone);\n const sign = offset < 0 ? '-' : '+';\n const abs = Math.abs(offset);\n const pad = (value: number, length = 2): string => String(value).padStart(length, '0');\n\n return `${pad(year, 4)}-${pad(month)}-${pad(day)}T${pad(time.hour)}:${pad(time.minute)}:00${sign}${pad(Math.floor(abs / 60))}:${pad(abs % 60)}`;\n}\n\n/**\n * The day and time of an ISO timestamp in a zone (Nepal by default). A value\n * without an offset (\"2026-10-18T14:30\", as from <input type=\"datetime-local\">)\n * is read as a wall time already in that zone. Null for anything else.\n */\nexport function fromIsoDateTime(\n value: string | null | undefined,\n timeZone: string = getConfig().timeZone,\n): { readonly date: AdDate; readonly time: TimeOfDay } | null {\n const zoned = fromIsoTimestamp(value, timeZone);\n if (zoned) {\n const time = parseTime(zoned.time);\n return time ? { date: zoned.date, time } : null;\n }\n const local = /^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2})(?::\\d{2}(?:\\.\\d+)?)?$/.exec(\n value ?? '',\n );\n if (!local) {\n return null;\n }\n try {\n return {\n date: adDate(Number(local[1]), Number(local[2]), Number(local[3])),\n time: timeOfDay(Number(local[4]), Number(local[5])),\n };\n } catch {\n return null;\n }\n}\n\n/** Minutes the zone is ahead of UTC at an instant. */\nfunction offsetMinutes(instant: number, timeZone: string): number {\n let parts: Intl.DateTimeFormatPart[];\n try {\n parts = new Intl.DateTimeFormat('en-US', {\n timeZone,\n hourCycle: 'h23',\n year: 'numeric',\n month: 'numeric',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n }).formatToParts(new Date(instant));\n } catch {\n throw new NepDateRangeError('INVALID_ARGUMENT', `\"${timeZone}\" is not a time zone.`);\n }\n const part = (type: Intl.DateTimeFormatPartTypes): number =>\n Number(parts.find((item) => item.type === type)?.value ?? 0);\n const wall = Date.UTC(\n part('year'),\n part('month') - 1,\n part('day'),\n part('hour'),\n part('minute'),\n );\n\n return Math.round((wall - Math.floor(instant / 60_000) * 60_000) / 60_000);\n}\n"],"mappings":";;;;AASA,IAAa,oBAAb,cAAuC,WAAW;CAGhD,YAAY,MAA6B,SAAiB;EACxD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;AAMA,IAAa,mBAAb,cAAsC,MAAM;CAO1C,YACE,MACA,SACA,MACA,OACA;EACA,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,QAAQ;CACf;AACF;;;;ACtCA,SAAgB,WAAW,OAAyB;CAClD,IAAI,CAAC,OAAO,cAAc,KAAK,GAC7B,MAA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OAAO,OAAO;GAAE,MAAM,MAAM;GAAM;EAAK,IAAI;CAC7C;CACA,MAAM,QAAQ,iEAAiE,KAC7E,SAAS,EACX;CACA,IAAI,CAAC,OACH,OAAO;CAET,IAAI;EACF,OAAO;GACL,MAAM,OAAO,OAAO,MAAM,EAAE,GAAG,OAAO,MAAM,EAAE,GAAG,OAAO,MAAM,EAAE,CAAC;GACjE,MAAM,UAAU,OAAO,MAAM,EAAE,GAAG,OAAO,MAAM,EAAE,CAAC;EACpD;CACF,QAAQ;EACN,OAAO;CACT;AACF;;AAGA,SAAS,cAAc,SAAiB,UAA0B;CAChE,IAAI;CACJ,IAAI;EACF,QAAQ,IAAI,KAAK,eAAe,SAAS;GACvC;GACA,WAAW;GACX,MAAM;GACN,OAAO;GACP,KAAK;GACL,MAAM;GACN,QAAQ;EACV,CAAC,CAAC,CAAC,cAAc,IAAI,KAAK,OAAO,CAAC;CACpC,QAAQ;EACN,MAAM,IAAI,kBAAkB,oBAAoB,IAAI,SAAS,sBAAsB;CACrF;CACA,MAAM,QAAQ,SACZ,OAAO,MAAM,MAAM,SAAS,KAAK,SAAS,IAAI,CAAC,EAAE,SAAS,CAAC;CAC7D,MAAM,OAAO,KAAK,IAChB,KAAK,MAAM,GACX,KAAK,OAAO,IAAI,GAChB,KAAK,KAAK,GACV,KAAK,MAAM,GACX,KAAK,QAAQ,CACf;CAEA,OAAO,KAAK,OAAO,OAAO,KAAK,MAAM,UAAU,GAAM,IAAI,OAAU,GAAM;AAC3E"}
@@ -0,0 +1,433 @@
1
+ //#region src/types.d.ts
2
+ /** The two calendars this library knows. */
3
+ type CalendarSystem = "AD" | "BS";
4
+ /**
5
+ * Whole days since 1970-01-01 AD. The only value the AD and BS calendars share:
6
+ * every conversion goes BS → EpochDay → AD and back (docs/plan D-001, D-002).
7
+ * Branded so a year, month or day number can never be passed by mistake.
8
+ */
9
+ type EpochDay = number & {
10
+ readonly __brand: "EpochDay";
11
+ };
12
+ /** 0 = Sunday … 6 = Saturday. */
13
+ type Weekday = 0 | 1 | 2 | 3 | 4 | 5 | 6;
14
+ /** 1 = Baisakh/January … 12 = Chaitra/December. */
15
+ type MonthNumber = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
16
+ /** A Gregorian (AD) calendar day. Create with `adDate()`; always frozen. */
17
+ interface AdDate {
18
+ readonly calendar: "AD";
19
+ readonly year: number;
20
+ readonly month: MonthNumber;
21
+ readonly day: number;
22
+ }
23
+ /** A Bikram Sambat (BS) calendar day. Create with `bsDate()`; always frozen. */
24
+ interface BsDate {
25
+ readonly calendar: "BS";
26
+ readonly year: number;
27
+ readonly month: MonthNumber;
28
+ readonly day: number;
29
+ }
30
+ type CalendarDate = AdDate | BsDate;
31
+ /** The date type of a calendar: `DateOf<'BS'>` is `BsDate`. */
32
+ type DateOf<C extends CalendarSystem> = C extends "AD" ? AdDate : BsDate;
33
+ /** The BS month-length table. Keyed by BS year only; holds no AD dates (D-001). */
34
+ interface BsData {
35
+ /** The BS year of the first row of `years`. */
36
+ readonly firstYear: number;
37
+ /** Days since 1970-01-01 of 1 Baisakh of `firstYear`. */
38
+ readonly epochStart: number;
39
+ /** Years after this one are projections, not yet checked against a published calendar. */
40
+ readonly verifiedThrough: number;
41
+ /** Twelve month lengths (Baisakh..Chaitra) per year, starting at `firstYear`. */
42
+ readonly years: readonly (readonly number[])[];
43
+ }
44
+ /** A locale code: built in are `en` and `ne`; more can be added with `registerLocale`. */
45
+ type LocaleCode = "en" | "ne" | (string & Record<never, never>);
46
+ /** Nepal's fiscal year: 1 Shrawan to the last day of Asar. */
47
+ interface FiscalYear {
48
+ /** The BS year the fiscal year starts in: 2083 for FY 2083/84. */
49
+ readonly startYear: number;
50
+ /** "2083/84" */
51
+ readonly label: string;
52
+ readonly firstDay: BsDate;
53
+ readonly lastDay: BsDate;
54
+ }
55
+ //#endregion
56
+ //#region src/errors.d.ts
57
+ type NepDateRangeErrorCode = "INVALID_DATE" | "OUT_OF_TABLE" | "INVALID_ARGUMENT";
58
+ /** Thrown for any invalid date or argument. Check `code`, not the message. */
59
+ export declare class NepDateRangeError extends RangeError {
60
+ readonly code: NepDateRangeErrorCode;
61
+ constructor(code: NepDateRangeErrorCode, message: string);
62
+ }
63
+ type NepDateDataErrorCode = "EMPTY" | "BAD_MONTH_COUNT" | "BAD_MONTH" | "BAD_YEAR_TOTAL" | "BAD_ANCHOR";
64
+ /** Thrown when a BS table passed to `setBsData` or `patchBsYear` is not valid. */
65
+ export declare class NepDateDataError extends Error {
66
+ readonly code: NepDateDataErrorCode;
67
+ /** The BS year at fault, when there is one. */
68
+ readonly year: number | undefined;
69
+ /** The month (1–12) at fault, when there is one. */
70
+ readonly month: number | undefined;
71
+ constructor(code: NepDateDataErrorCode, message: string, year?: number, month?: number);
72
+ }
73
+ //#endregion
74
+ //#region src/epoch.d.ts
75
+ /** Brand a whole number of days since 1970-01-01 as an `EpochDay`. */
76
+ export declare function toEpochDay(value: number): EpochDay;
77
+ /** The weekday of a day count. 1970-01-01 was a Thursday. */
78
+ export declare function weekdayOf(epoch: EpochDay): Weekday;
79
+ //#endregion
80
+ //#region src/config.d.ts
81
+ /**
82
+ * Settings shared by both calendars. Calendar data is not here: the BS table is
83
+ * managed by setBsData/patchBsYear, and AD needs no data (docs/plan D-001).
84
+ */
85
+ interface NepDateConfig {
86
+ /** Which time zone decides "today" and the calendar day of an instant. */
87
+ readonly timeZone: string;
88
+ readonly weekStartsOn: Weekday;
89
+ readonly weekendDays: readonly Weekday[];
90
+ readonly defaultLocale: LocaleCode;
91
+ }
92
+ /** Change one or more settings. Every value is checked before any is applied. */
93
+ export declare function configure(changes: Partial<NepDateConfig>): void;
94
+ export declare function getConfig(): NepDateConfig;
95
+ /** Back to the defaults (Kathmandu, Sunday first, Saturday weekend, English). */
96
+ export declare function resetConfig(): void;
97
+ //#endregion
98
+ //#region src/ad/calendar.d.ts
99
+ /**
100
+ * The Gregorian (AD) calendar, by arithmetic only: no table, no BS knowledge,
101
+ * no `Date`. Works for any year in ±MAX_AD_YEAR (docs/plan D-001).
102
+ *
103
+ * The day-count algorithms are Howard Hinnant's days_from_civil and
104
+ * civil_from_days (proleptic Gregorian, March-based years).
105
+ */
106
+ /** AD years must lie within ±this value. */
107
+ export declare const MAX_AD_YEAR = 999999;
108
+ export declare function isAdLeapYear(year: number): boolean;
109
+ //#endregion
110
+ //#region src/bs/table.d.ts
111
+ export declare function bsFirstYear(): number;
112
+ export declare function bsLastYear(): number;
113
+ //#endregion
114
+ //#region src/bs/data-api.d.ts
115
+ /** The first BS month of Nepal's fiscal year: Shrawan. */
116
+ export declare const BS_FISCAL_YEAR_START_MONTH = 4;
117
+ /** Throws NepDateDataError when the table is not usable. Same rules as scripts/gen-data.ts. */
118
+ export declare function validateBsData(table: BsData): void;
119
+ /** The BS table in use (frozen). */
120
+ export declare function getBsData(): BsData;
121
+ /** Replace the whole BS table. Only BS results change; AD functions are unaffected. */
122
+ export declare function setBsData(table: BsData): void;
123
+ /**
124
+ * Correct one year's month lengths, or add the year just before the first or
125
+ * just after the last. Years after a corrected year move with it; earlier years
126
+ * never move (adding a year before the first keeps every existing year in place).
127
+ */
128
+ export declare function patchBsYear(year: number, months: readonly number[]): void;
129
+ /** Back to the table bundled with the package. */
130
+ export declare function resetBsData(): void;
131
+ //#endregion
132
+ //#region src/create.d.ts
133
+ /** An AD date. Any year within ±999,999 is allowed; only conversion to BS is limited. */
134
+ export declare function adDate(year: number, month: number, day: number): AdDate;
135
+ /** A BS date. The year must be in the BS table. */
136
+ export declare function bsDate(year: number, month: number, day: number): BsDate;
137
+ export declare function createDate<C extends CalendarSystem>(calendar: C, year: number, month: number, day: number): DateOf<C>;
138
+ export declare function isValidDate(calendar: CalendarSystem, year: number, month: number, day: number): boolean;
139
+ /** Days in a month of either calendar. */
140
+ export declare function daysInMonth(calendar: CalendarSystem, year: number, month: number): number;
141
+ /** True for a valid, frozen-or-not AD date object (e.g. from JSON). */
142
+ export declare function isAdDate(value: unknown): value is AdDate;
143
+ /** True for a valid BS date object (e.g. from JSON). */
144
+ export declare function isBsDate(value: unknown): value is BsDate;
145
+ export declare function isCalendarDate(value: unknown): value is CalendarDate;
146
+ //#endregion
147
+ //#region src/convert.d.ts
148
+ /** The day count of a date in either calendar. */
149
+ export declare function toEpoch(date: CalendarDate): EpochDay;
150
+ /** The date of a day count in a calendar. BS throws OUT_OF_TABLE outside the table. */
151
+ export declare function fromEpoch<C extends CalendarSystem>(epoch: EpochDay, calendar: C): DateOf<C>;
152
+ export declare function adToBs(date: AdDate): BsDate;
153
+ export declare function bsToAd(date: BsDate): AdDate;
154
+ /** The same day in the given calendar (the date itself when it is already in it). */
155
+ export declare function toCalendar<C extends CalendarSystem>(date: CalendarDate, calendar: C): DateOf<C>;
156
+ /** The first day that can be converted, in either calendar (the start of the BS table). */
157
+ export declare function minDate<C extends CalendarSystem>(calendar: C): DateOf<C>;
158
+ /** The last day that can be converted, in either calendar (the end of the BS table). */
159
+ export declare function maxDate<C extends CalendarSystem>(calendar: C): DateOf<C>;
160
+ /** Whether a date can be converted to the other calendar. */
161
+ export declare function isConvertible(date: CalendarDate): boolean;
162
+ /** The AD day as "YYYY-MM-DD", the form to store and send (docs/plan D-003). */
163
+ export declare function toIsoDate(date: CalendarDate): string;
164
+ /**
165
+ * An AD date from "YYYY-MM-DD", or from a longer ISO timestamp by its date part
166
+ * ("2026-10-18T09:30:00Z" → 2026-10-18). Null for anything else.
167
+ */
168
+ export declare function fromIsoDate(value: string | null | undefined): AdDate | null;
169
+ /** The AD calendar day an instant falls on in a time zone (Nepal by default). */
170
+ export declare function fromJsDate(instant: Date, timeZone?: string): AdDate;
171
+ /**
172
+ * The calendar day and time of an ISO timestamp *with a zone* ("…Z",
173
+ * "…+05:45"), read in `timeZone` (Nepal by default). Null for anything else,
174
+ * including plain dates, which have no instant.
175
+ */
176
+ export declare function fromIsoTimestamp(value: string | null | undefined, timeZone?: string): {
177
+ readonly date: AdDate;
178
+ readonly time: string;
179
+ } | null;
180
+ //#endregion
181
+ //#region src/projected.d.ts
182
+ /** Whether the date's BS year is after the last year checked against a published calendar. */
183
+ export declare function isProjected(date: CalendarDate): boolean;
184
+ //#endregion
185
+ //#region src/clock.d.ts
186
+ /**
187
+ * Today's date by the calendar day in `timeZone` (Nepal by default), not the
188
+ * device's zone. The only function in the library that reads the clock.
189
+ */
190
+ export declare function today(): AdDate;
191
+ export declare function today<C extends CalendarSystem>(calendar: C, timeZone?: string): DateOf<C>;
192
+ /** The current calendar day and time (HH:MM) in `timeZone` (Nepal by default). */
193
+ export declare function now(timeZone?: string): {
194
+ readonly date: AdDate;
195
+ readonly time: {
196
+ readonly hour: number;
197
+ readonly minute: number;
198
+ };
199
+ };
200
+ //#endregion
201
+ //#region src/arithmetic.d.ts
202
+ /** A date in the same calendar as `D`. */
203
+ type Same<D extends CalendarDate> = DateOf<D["calendar"]>;
204
+ export declare function addDays<D extends CalendarDate>(date: D, days: number): Same<D>;
205
+ /** Move by whole months in the date's own calendar; the day is capped to the new month's length. */
206
+ export declare function addMonths<D extends CalendarDate>(date: D, months: number): Same<D>;
207
+ /** Move by whole years in the date's own calendar; the day is capped (29 Feb, short BS months). */
208
+ export declare function addYears<D extends CalendarDate>(date: D, years: number): Same<D>;
209
+ export declare function startOfMonth<D extends CalendarDate>(date: D): Same<D>;
210
+ export declare function endOfMonth<D extends CalendarDate>(date: D): Same<D>;
211
+ export declare function startOfYear<D extends CalendarDate>(date: D): Same<D>;
212
+ export declare function endOfYear<D extends CalendarDate>(date: D): Same<D>;
213
+ export declare function startOfWeek<D extends CalendarDate>(date: D, weekStartsOn?: Weekday): Same<D>;
214
+ export declare function endOfWeek<D extends CalendarDate>(date: D, weekStartsOn?: Weekday): Same<D>;
215
+ /** Whole days from `b` to `a` (positive when `a` is later). The calendars may differ. */
216
+ export declare function differenceInDays(a: CalendarDate, b: CalendarDate): number;
217
+ /** Every day from `start` to `end` inclusive, in `start`'s calendar. Nothing when end < start. */
218
+ export declare function eachDayOfInterval<D extends CalendarDate>(start: D, end: CalendarDate): Generator<Same<D>, void, undefined>;
219
+ /** Every day of the month the date is in. */
220
+ export declare function eachDayOfMonth<D extends CalendarDate>(date: D): Same<D>[];
221
+ //#endregion
222
+ //#region src/compare.d.ts
223
+ type Maybe = CalendarDate | null | undefined;
224
+ /** -1, 0 or 1. Dates in different calendars compare by the day they fall on. */
225
+ export declare function compareDates(a: CalendarDate, b: CalendarDate): -1 | 0 | 1;
226
+ /** Same day, in any calendars. False when either is missing. */
227
+ export declare function isSameDay(a: Maybe, b: Maybe): boolean;
228
+ /** Whether `b` falls in the same month as `a`, judged in `a`'s calendar. */
229
+ export declare function isSameMonth(a: CalendarDate, b: CalendarDate): boolean;
230
+ /** Whether `b` falls in the same year as `a`, judged in `a`'s calendar. */
231
+ export declare function isSameYear(a: CalendarDate, b: CalendarDate): boolean;
232
+ export declare function isBefore(a: CalendarDate, b: CalendarDate): boolean;
233
+ export declare function isAfter(a: CalendarDate, b: CalendarDate): boolean;
234
+ /** On or after `min` and on or before `max`; a missing bound is open. */
235
+ export declare function isWithin(date: CalendarDate, min?: Maybe, max?: Maybe): boolean;
236
+ /** The date, or the nearest bound when it is outside, in the date's calendar. */
237
+ export declare function clampDate<D extends CalendarDate>(date: D, min?: Maybe, max?: Maybe): DateOf<D["calendar"]>;
238
+ /** 0 = Sunday … 6 = Saturday. The same in both calendars. */
239
+ export declare function dayOfWeek(date: CalendarDate): Weekday;
240
+ /** Saturday by default (Nepal); set `weekendDays` in configure() or pass them here. */
241
+ export declare function isWeekend(date: CalendarDate, weekendDays?: readonly Weekday[]): boolean;
242
+ //#endregion
243
+ //#region src/locale/registry.d.ts
244
+ type Names12 = readonly string[];
245
+ /** Everything a language needs: digits, names, UI labels and validation messages. */
246
+ interface LocaleData {
247
+ /** Ten digit characters, 0–9. */
248
+ readonly digits: readonly string[];
249
+ /** Seven names each, Sunday first. */
250
+ readonly weekdays: {
251
+ readonly long: readonly string[];
252
+ readonly short: readonly string[];
253
+ readonly narrow: readonly string[];
254
+ };
255
+ /** Twelve names each, first month first. */
256
+ readonly months: {
257
+ readonly AD: {
258
+ readonly long: Names12;
259
+ readonly short: Names12;
260
+ };
261
+ readonly BS: {
262
+ readonly long: Names12;
263
+ readonly short: Names12;
264
+ };
265
+ };
266
+ /** How each calendar is named in this language: "BS" / "वि.सं.". */
267
+ readonly calendarNames: {
268
+ readonly AD: string;
269
+ readonly BS: string;
270
+ };
271
+ readonly labels: {
272
+ readonly today: string;
273
+ readonly clear: string;
274
+ readonly previousMonth: string;
275
+ readonly nextMonth: string;
276
+ readonly previousYear: string;
277
+ readonly nextYear: string;
278
+ readonly month: string;
279
+ readonly year: string;
280
+ readonly openCalendar: string;
281
+ readonly chooseDate: string;
282
+ readonly calendar: string;
283
+ /** Picker shortcuts (presets) and the name of their list. */
284
+ readonly presets: string;
285
+ readonly fiscalYear: string;
286
+ readonly time: string;
287
+ readonly hour: string;
288
+ readonly minute: string;
289
+ readonly now: string;
290
+ readonly done: string;
291
+ };
292
+ /** Words for 12-hour times. */
293
+ readonly time: {
294
+ readonly am: string;
295
+ readonly pm: string;
296
+ };
297
+ /** Names of the built-in picker presets. */
298
+ readonly presets: {
299
+ readonly today: string;
300
+ readonly yesterday: string;
301
+ readonly tomorrow: string;
302
+ readonly thisWeek: string;
303
+ readonly lastWeek: string;
304
+ readonly last7Days: string;
305
+ readonly last30Days: string;
306
+ readonly thisMonth: string;
307
+ readonly lastMonth: string;
308
+ readonly thisYear: string;
309
+ readonly thisFiscalYear: string;
310
+ readonly lastFiscalYear: string;
311
+ };
312
+ /** Messages may use {min} and {max} placeholders. */
313
+ readonly messages: {
314
+ readonly invalidFormat: {
315
+ readonly AD: string;
316
+ readonly BS: string;
317
+ };
318
+ readonly outOfRange: string;
319
+ readonly onOrAfter: string;
320
+ readonly onOrBefore: string;
321
+ readonly unavailable: string;
322
+ /** Range pickers: {min} / {max} are day counts. */
323
+ readonly rangeTooShort: string;
324
+ readonly rangeTooLong: string;
325
+ /** Multiple-date pickers: {max} is a count of dates. */
326
+ readonly tooManyDates: string;
327
+ readonly invalidTime: string;
328
+ };
329
+ }
330
+ /** Add or replace a language. Lists must have the right lengths (10 digits, 7 weekdays, 12 months). */
331
+ export declare function registerLocale(code: LocaleCode, data: LocaleData): void;
332
+ export declare function hasLocale(code: LocaleCode): boolean;
333
+ //#endregion
334
+ //#region src/locale/index.d.ts
335
+ /** The data for a locale (the configured default when omitted; English when unknown). */
336
+ export declare function getLocale(locale?: LocaleCode): LocaleData;
337
+ export declare function monthNames(calendar: CalendarSystem, locale?: LocaleCode, width?: "long" | "short"): readonly string[];
338
+ export declare function weekdayNames(locale?: LocaleCode, width?: "long" | "short" | "narrow"): readonly string[];
339
+ /** Replace Devanagari digits with ASCII digits. */
340
+ export declare function toAsciiDigits(value: string): string;
341
+ /** Replace ASCII digits with Devanagari digits. */
342
+ export declare function toDevanagariDigits(value: string | number): string;
343
+ /** Write a number (or digit string) with the locale's digits. */
344
+ export declare function formatNumber(value: string | number, locale?: LocaleCode): string;
345
+ /** Fill {name} placeholders in a locale message. */
346
+ export declare function formatMessage(template: string, values: Record<string, string>): string;
347
+ //#endregion
348
+ //#region src/format.d.ts
349
+ /** Named formats. `cbms` is the dotted form Nepal's tax system uses. */
350
+ export declare const DATE_FORMATS: {
351
+ readonly iso: "Y-m-d";
352
+ readonly cbms: "Y.m.d";
353
+ readonly short: "j M Y";
354
+ readonly long: "j F Y";
355
+ readonly full: "l, j F Y";
356
+ };
357
+ type NamedFormat = keyof typeof DATE_FORMATS;
358
+ /** A named format, or a pattern of tokens (see formatDate). */
359
+ type DateFormatPattern = NamedFormat | (string & Record<never, never>);
360
+ /**
361
+ * Format a date in its own calendar. Tokens: Y 2083, y 83, m 06, n 6, d 09,
362
+ * j 9, F month name, M short month name, l weekday, D short weekday. Put a
363
+ * backslash before a letter to print it as is. Digits follow the locale.
364
+ *
365
+ * formatDate(bsDate(2082, 4, 1), 'full') → "Thursday, 1 Shrawan 2082"
366
+ * formatDate(bsDate(2082, 4, 1), 'long', 'ne') → "१ साउन २०८२"
367
+ */
368
+ export declare function formatDate(date: CalendarDate, pattern?: DateFormatPattern, locale?: LocaleCode): string;
369
+ //#endregion
370
+ //#region src/parse.d.ts
371
+ /**
372
+ * A date written year first ("2083-06-24", "2083/6/24", "2083.06.24", or
373
+ * compact "20830624") in ASCII or Devanagari digits, in the calendar the caller names. Other orders are
374
+ * rejected, not guessed. Returns null when the text is not a valid date.
375
+ */
376
+ export declare function parseDate<C extends CalendarSystem>(text: string | null | undefined, calendar: C): DateOf<C> | null;
377
+ /** Like parseDate, but throws a NepDateRangeError that says what is wrong. */
378
+ export declare function parseDateStrict<C extends CalendarSystem>(text: string, calendar: C): DateOf<C>;
379
+ /**
380
+ * A fiscal year from its label: "2083/84", "2083/2084", "2083-84" or the
381
+ * tax form "2083.084", in ASCII or Devanagari digits. Null when not valid.
382
+ */
383
+ export declare function parseFiscalYear(text: string | null | undefined): FiscalYear | null;
384
+ //#endregion
385
+ //#region src/fiscal.d.ts
386
+ /** The fiscal year a date falls in: 1 Shrawan to the end of Asar. */
387
+ export declare function fiscalYear(date: CalendarDate): FiscalYear;
388
+ /** The fiscal year that starts in BS `startYear` (2083 → FY 2083/84). */
389
+ export declare function fiscalYearRange(startYear: number): FiscalYear;
390
+ /**
391
+ * label "2083/84" · full "2083/2084" · cbms "2083.084" (the form Nepal's tax
392
+ * system uses). Digits follow the locale.
393
+ */
394
+ export declare function formatFiscalYear(fy: FiscalYear, style?: "label" | "full" | "cbms", locale?: LocaleCode): string;
395
+ export declare function isInFiscalYear(date: CalendarDate, fy: FiscalYear): boolean;
396
+ //#endregion
397
+ //#region src/time.d.ts
398
+ /** A time of day, 00:00–23:59. Frozen like dates. */
399
+ interface TimeOfDay {
400
+ readonly hour: number;
401
+ readonly minute: number;
402
+ }
403
+ export declare function timeOfDay(hour: number, minute?: number): TimeOfDay;
404
+ export declare function isValidTime(hour: number, minute: number): boolean;
405
+ /** -1, 0 or 1. */
406
+ export declare function compareTimes(a: TimeOfDay, b: TimeOfDay): -1 | 0 | 1;
407
+ /**
408
+ * "14:30", "2:30 pm", "2 PM", "1430", "१४:३०", "२:३० अपराह्न" → TimeOfDay.
409
+ * Null when the text is not a time.
410
+ */
411
+ export declare function parseTime(text: string | null | undefined): TimeOfDay | null;
412
+ /** "14:30" (24-hour) or "2:30 PM" (hour12), in the locale's digits and words. */
413
+ export declare function formatTime(time: TimeOfDay, options?: {
414
+ readonly hour12?: boolean;
415
+ readonly locale?: LocaleCode;
416
+ }): string;
417
+ /**
418
+ * The instant of a calendar day and time in a zone (Nepal by default), as an
419
+ * ISO timestamp with that zone's offset: "2026-10-18T14:30:00+05:45".
420
+ */
421
+ export declare function toIsoDateTime(date: CalendarDate, time: TimeOfDay, timeZone?: string): string;
422
+ /**
423
+ * The day and time of an ISO timestamp in a zone (Nepal by default). A value
424
+ * without an offset ("2026-10-18T14:30", as from <input type="datetime-local">)
425
+ * is read as a wall time already in that zone. Null for anything else.
426
+ */
427
+ export declare function fromIsoDateTime(value: string | null | undefined, timeZone?: string): {
428
+ readonly date: AdDate;
429
+ readonly time: TimeOfDay;
430
+ } | null;
431
+ //#endregion
432
+ export type { AdDate, BsData, BsDate, CalendarDate, CalendarSystem, DateFormatPattern, DateOf, EpochDay, FiscalYear, LocaleCode, LocaleData, MonthNumber, NamedFormat, NepDateConfig, NepDateDataErrorCode, NepDateRangeErrorCode, TimeOfDay, Weekday };
433
+ //# sourceMappingURL=index.d.cts.map