UNPKG

@brightsoftware/date-np

Version:

Simple & minimal Nepali date picker that just works.

37 lines (36 loc) 1.59 kB
import { MIN_BS_YEAR as u, AD_MONTH as l, AD_MONTH_LEAP_YEAR as g, MIN_AD_YEAR as D, MAX_BS_YEAR as m } from "../data/constants.js"; import { extractYear as a } from "./helpers.js"; import { NepaliDate as o } from "../src/NepaliDate.js"; const N = (e) => a(e) >= Number(u), _ = (e) => a(e) >= Number(D), Y = (e) => { const t = a(e); let n = t % 4 === 0; return t % 100 === 0 && (n = t % 400 === 0), n; }, h = (e) => { const t = e.getFullYear(), n = e.getMonth(), r = e.getDate(); return !(n < 0 || n > 11 || r < 1 || r > l[n] || Y(e) && r > g[n] || t < D || t > m); }, E = (e, t) => { if (e instanceof o && t instanceof o) return e.equals(t); if (e instanceof Date && t instanceof Date) return e.getFullYear() === t.getFullYear() && e.getMonth() === t.getMonth() && e.getDate() === t.getDate(); const n = e instanceof o ? e.toADDate() : e, r = t instanceof o ? t.toADDate() : t; return n.getFullYear() === r.getFullYear() && n.getMonth() === r.getMonth() && n.getDate() === r.getDate(); }, A = (e, t) => { if (e instanceof o && t instanceof o) return e.compare(t); if (e instanceof Date && t instanceof Date) { const c = e.getTime(), f = t.getTime(); return c < f ? -1 : c > f ? 1 : 0; } const n = e instanceof o ? e.toADDate() : e, r = t instanceof o ? t.toADDate() : t, s = n.getTime(), i = r.getTime(); return s < i ? -1 : s > i ? 1 : 0; }, R = (e, t) => A(e, t) > 0; export { E as areDatesEqual, A as compareDates, Y as isADLeapYear, R as isInvalidDateRange, h as isValidADRange, _ as isValidADYear, N as isValidBSYear };