nepali-datepicker-vue2
Version:
A Vue 2 Nepali Datepicker
625 lines (624 loc) • 37.1 kB
JavaScript
var $ = Object.defineProperty;
var O = (e, t, a) => t in e ? $(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
var g = (e, t, a) => O(e, typeof t != "symbol" ? t + "" : t, a);
var i = [{ year: 2e3, days: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2001, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2002, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2003, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2004, days: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2005, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2006, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2007, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2008, days: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2009, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2010, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2011, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2012, days: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2013, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2014, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2015, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2016, days: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2017, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2018, days: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2019, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2020, days: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2021, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2022, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2023, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2024, days: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2025, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2026, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2027, days: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2028, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2029, days: [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2030, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2031, days: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2032, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2033, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2034, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2035, days: [30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2036, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2037, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2038, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2039, days: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2040, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2041, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2042, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2043, days: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2044, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2045, days: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2046, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2047, days: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2048, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2049, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2050, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2051, days: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2052, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2053, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2054, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2055, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2056, days: [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2057, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2058, days: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2059, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2060, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2061, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2062, days: [30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2063, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2064, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2065, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2066, days: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2067, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2068, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2069, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2070, days: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2071, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2072, days: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2073, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2074, days: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2075, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2076, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2077, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2078, days: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2079, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2080, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2081, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2082, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2083, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2084, days: [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2085, days: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2086, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2087, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2088, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2089, days: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2090, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2091, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2092, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2093, days: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2094, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2095, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2096, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2097, days: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2098, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2099, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2100, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }], E = 0;
i.forEach((e) => {
e.totalDays = e.days.reduce((t, a) => t + a, 0), E += e.totalDays, e.daysTillNow = E;
});
var D = new Date(1943, 3, 14).getTime(), S = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], p = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], b = ["आइतबार", "सोमबार", "मंगलबार", "बुधबार", "बिहिबार", "शुक्रबार", "शनिबार"], V = ["आइत", "सोम", "मंगल", "बुध", "बिहि", "शुक्र", "शनि"], M = ["Baisakh", "Jestha", "Asar", "Shrawan", "Bhadra", "Aswin", "Kartik", "Mangsir", "Poush", "Magh", "Falgun", "Chaitra"], I = ["Bai", "Jes", "Asa", "Shr", "Bhd", "Asw", "Kar", "Man", "Pou", "Mag", "Fal", "Cha"], P = ["बैशाख", "जेठ", "असार", "श्रावण", "भाद्र", "आश्विन", "कार्तिक", "मंसिर", "पौष", "माघ", "फाल्गुण", "चैत्र"], A = ["बै", "जे", "अ", "श्रा", "भा", "आ", "का", "मं", "पौ", "मा", "फा", "चै"], Q = ["०", "१", "२", "३", "४", "५", "६", "७", "८", "९"];
function v(e) {
return e < 10 ? `0${e}` : `${e}`;
}
function m(e) {
let t = "";
for (let a = 0; a < e.length; a += 1) t += Q[e.charCodeAt(a) - 48];
return t;
}
function x(e) {
return (t) => e <= 2 ? String(t.getYear()).substring(2) : e === 3 ? String(t.getYear()).substring(1) : String(t.getYear());
}
function R(e) {
return (t) => e <= 2 ? m(String(t.getYear()).substring(2)) : m(e === 3 ? String(t.getYear()).substring(1) : String(t.getYear()));
}
function H(e) {
return (t) => e === 1 ? String(t.getMonth() + 1) : e === 2 ? v(t.getMonth() + 1) : e === 3 ? I[t.getMonth()] : M[t.getMonth()];
}
function B(e) {
return (t) => e === 1 ? m(String(t.getMonth() + 1)) : e === 2 ? m(v(t.getMonth() + 1)) : e === 3 ? A[t.getMonth()] : P[t.getMonth()];
}
function L(e) {
return (t) => e === 1 ? String(t.getDate()) : e === 2 ? v(t.getDate()) : e === 3 ? p[t.getDay()] : S[t.getDay()];
}
function W(e) {
return (t) => e === 1 ? m(String(t.getDate())) : e === 2 ? m(v(t.getDate())) : e === 3 ? V[t.getDay()] : b[t.getDay()];
}
function C(e) {
return () => e;
}
var Y = { Y: x, y: R, M: H, m: B, D: L, d: W };
function G(e) {
return e in Y;
}
function K(e) {
let t = !1, a = "", s = "", r = 0, n = [];
for (let y = 0; y < e.length; y += 1) {
let d = e[y];
if (d === s) {
r += 1;
continue;
}
if (s !== "" && (n.push(Y[s](r)), s = "", r = 0), d === '"') {
t = !t;
continue;
}
!G(d) || t ? a += d : (a && (n.push(C(a)), a = ""), s = d, r = 1);
}
return a ? n.push(C(a)) : s && n.push(Y[s](r)), n;
}
function j(e, t) {
return K(t).map((a) => a(e)).join("");
}
function k(e) {
let t = e.split(/[-./]/, 3), [a, s = 1, r = 1] = t.map((y) => {
let d = parseInt(y, 10);
if (Number.isNaN(d)) throw new Error("Invalid date");
return d;
});
if (a < i[0].year || a >= i[0].year + i.length) throw new Error("Nepal year out of range");
if (s < 1 || s > 12) throw new Error("Invalid nepali month must be between 1 - 12");
let n = i[a - i[0].year].days[s - 1];
if (r < 1 || r > n) throw new Error(`Invalid nepali date must be between 1 - ${n} in ${a} ${s}`);
return [a, s - 1, r];
}
var o = class l {
constructor(...t) {
g(this, "timestamp");
g(this, "year");
g(this, "month");
g(this, "day");
if (t.length === 0) this.setEnglishDate(/* @__PURE__ */ new Date());
else if (t.length === 1) {
let a = t[0];
if (typeof a == "object") if (a instanceof Date) this.setEnglishDate(a);
else if (a instanceof l) this.timestamp = a.timestamp, this.year = a.year, this.month = a.month, this.day = a.day;
else throw new Error("Invalid date argument");
else if (typeof a == "string") this.set(...k(a));
else if (typeof a == "number") this.setEnglishDate(new Date(a));
else throw new Error("Invalid date argument");
} else if (t.length === 3) this.set(t[0], t[1], t[2]);
else throw new Error("Invalid argument syntax");
}
setEnglishDate(t) {
this.timestamp = t;
let a = Math.floor((this.timestamp.getTime() - D) / 864e5), s = Math.floor(a / 366);
for (; a >= i[s].daysTillNow; ) s += 1;
let r = i[s - 1] ? i[s - 1].daysTillNow : 0;
a -= r;
let n = i[s];
for (this.year = n.year, this.month = 0; a >= n.days[this.month]; ) this.month += 1, a -= n.days[this.month - 1];
this.day = a + 1;
}
getEnglishDate() {
return this.timestamp;
}
parse(t) {
this.set(...k(t));
}
getYear() {
return this.year;
}
getMonth() {
return this.month;
}
getDate() {
return this.day;
}
getDay() {
return this.timestamp.getDay();
}
getHours() {
return this.timestamp.getHours();
}
getMinutes() {
return this.timestamp.getMinutes();
}
getSeconds() {
return this.timestamp.getSeconds();
}
getMilliseconds() {
return this.timestamp.getMilliseconds();
}
getTime() {
return this.timestamp.getTime();
}
setYear(t) {
this.set(t, this.month, this.day);
}
setMonth(t) {
this.set(this.year, t, this.day);
}
setDate(t) {
this.set(this.year, this.month, t);
}
set(t, a, s) {
let r = t + Math.floor(a / 12) - i[0].year, n = i[r], y = n.daysTillNow - n.totalDays, d = a % 12, u = d < 0 ? 12 + d : d;
for (let h = 0; h < u; h += 1) y += n.days[h];
y += s - 1, this.setEnglishDate(new Date(D + y * 864e5));
}
format(t) {
return j(this, t);
}
toString() {
return `${this.year}/${this.month + 1}/${this.day}`;
}
addDays(t) {
let a = new Date(this.timestamp.getTime() + t * 864e5);
return new l(a);
}
addMonths(t) {
let a = this.year, s = this.month + t;
a += Math.floor(s / 12), s = s % 12, s < 0 && (s += 12, a -= 1);
let r = a - i[0].year;
if (r < 0 || r >= i.length) throw new Error("Resulting date is out of supported range");
let n = i[r].days[s], y = Math.min(this.day, n);
return new l(a, s, y);
}
addYears(t) {
let a = this.year + t;
if (a < i[0].year || a >= i[0].year + i.length) throw new Error("Resulting date is out of supported range");
let s = a - i[0].year;
if (this.month === 11 && this.day === 29) {
let r = i[s].days[11];
if (r < 29) return new l(a, 11, r);
}
return new l(a, this.month, this.day);
}
static minimum() {
return new Date(D);
}
static maximum() {
return new Date(D + i[i.length - 1].daysTillNow * 864e5);
}
daysInMonth() {
let t = this.year - i[0].year;
return i[t].days[this.month];
}
isLeapYear() {
let t = this.year - i[0].year;
return i[t].totalDays === 366;
}
getWeeksInMonth() {
let t = new l(this.year, this.month, 1).getDay(), a = this.daysInMonth();
return Math.ceil((t + a) / 7);
}
diff(t, a) {
switch (a) {
case "day":
return Math.floor((this.timestamp.getTime() - t.timestamp.getTime()) / 864e5);
case "month":
let s = this.year - t.year, r = this.month - t.month;
return s * 12 + r;
case "year":
return this.year - t.year;
default:
throw new Error("Invalid unit for diff calculation");
}
}
startOfDay() {
let t = new Date(this.timestamp);
return t.setHours(0, 0, 0, 0), new l(t);
}
endOfDay() {
let t = new Date(this.timestamp);
return t.setHours(23, 59, 59, 999), new l(t);
}
startOfWeek(t = 0) {
if (t < 0 || t > 6 || !Number.isInteger(t)) throw new Error("startOfWeek must be an integer between 0 and 6");
let a = (this.getDay() - t + 7) % 7;
return this.clone().startOfDay().addDays(-a);
}
endOfWeek(t = 0) {
return this.startOfWeek(t).addDays(6).endOfDay();
}
startOfMonth() {
return new l(this.year, this.month, 1);
}
endOfMonth() {
let t = this.daysInMonth();
return new l(this.year, this.month, t).endOfDay();
}
startOfYear() {
return new l(this.year, 0, 1);
}
endOfYear() {
let t = this.year - i[0].year, a = i[t].days[11];
return new l(this.year, 11, a).endOfDay();
}
static getMonthName(t, a = !1, s = !1) {
if (t < 0 || t > 11) throw new Error("Invalid month index, must be between 0-11");
let r = "";
return s ? r = a ? A[t] : P[t] : r = a ? I[t] : M[t], r;
}
static getDayName(t, a = !1, s = !1) {
if (t < 0 || t > 6) throw new Error("Invalid day index, must be between 0-6");
let r = "";
return s ? r = a ? V[t] : b[t] : r = a ? p[t] : S[t], r;
}
static isValid(t, a, s) {
try {
if (t < i[0].year || t >= i[0].year + i.length || a < 0 || a > 11) return !1;
let r = t - i[0].year, n = i[r].days[a];
return !(s < 1 || s > n);
} catch {
return !1;
}
}
isValid() {
return l.isValid(this.year, this.month, this.day);
}
static getCalendarDays(t, a) {
if (!l.isValid(t, a, 1)) throw new Error("Invalid year or month");
let s = { year: 0, month: 0, days: [] }, r = { year: 0, month: 0, days: [] }, n = { year: 0, month: 0, days: [] }, y = t - i[0].year, d = new l(t, a, 1).getDay(), u = i[y].days[a];
r.year = t, r.month = a;
let h = a - 1, w = t, _ = a + 1, f = t;
if (h < 0 && (h = 11, w--), w > i[0].year && (s.year = w, s.month = h), w >= i[0].year && d > 0) {
let c = w - i[0].year, F = i[c].days[h];
for (let N = 0; N < d; N++) s.days.push(F - d + N + 1);
}
for (let c = 1; c <= u; c++) r.days.push(c);
_ > 11 && (_ = 0, f++), f < i[0].year + i.length && (n.year = f, n.month = _);
let T = 42 - d - r.days.length;
if (f < i[0].year + i.length && T > 0) for (let c = 1; c <= T; c++) n.days.push(c);
return { prevRemainingDays: d, prevMonth: s, currentMonth: r, nextMonth: n, remainingDays: T };
}
clone() {
return new l(this);
}
isAfter(t) {
return this.timestamp.getTime() > t.timestamp.getTime();
}
isBefore(t) {
return this.timestamp.getTime() < t.timestamp.getTime();
}
isEqual(t) {
return this.year === t.year && this.month === t.month && this.day === t.day;
}
isSame(t, a) {
switch (a) {
case "year":
return this.year === t.year;
case "month":
return this.year === t.year && this.month === t.month;
case "day":
return this.isEqual(t);
default:
throw new Error("Invalid unit for comparison");
}
}
static getQuarter(t, a) {
if (t < 1 || t > 4 || !Number.isInteger(t)) throw new Error("Quarter must be an integer between 1 and 4");
let s = a ?? new l().getYear(), r = (t - 1) * 3, n = new l(s, r, 1), y = new l(s, r + 2, 1).endOfMonth();
return { start: n, end: y };
}
getCurrentQuarter() {
return Math.floor(this.month / 3) + 1;
}
static getQuarters(t) {
let a = t ?? new l().getYear();
return { Q1: l.getQuarter(1, a), Q2: l.getQuarter(2, a), Q3: l.getQuarter(3, a), Q4: l.getQuarter(4, a) };
}
static getCurrentFiscalYear() {
let t = new l(), a = t.getYear();
return t.getMonth() < 3 ? a - 1 : a;
}
static getFiscalYearQuarter(t, a) {
if (t < 1 || t > 4 || !Number.isInteger(t)) throw new Error("Quarter must be an integer between 1 and 4");
let s = a ?? l.getCurrentFiscalYear(), r = s, n = (t - 1) * 3 + 3;
t === 4 && (r = s + 1, n = 0), n > 11 && (r++, n -= 12);
let y = n + 2, d = r;
y > 11 && (d++, y -= 12);
let u = new l(r, n, 1), h = new l(d, y, 1).endOfMonth();
return { start: u, end: h };
}
getCurrentFiscalYearQuarter() {
let t = this.getMonth();
return t >= 3 && t <= 5 ? 1 : t >= 6 && t <= 8 ? 2 : t >= 9 && t <= 11 ? 3 : 4;
}
getCurrentFiscalYearQuarterDates() {
let t = this.getCurrentFiscalYearQuarter(), a = l.getCurrentFiscalYear();
return l.getFiscalYearQuarter(t, a);
}
static getFiscalYearQuarters(t) {
let a = t ?? l.getCurrentFiscalYear();
return { Q1: l.getFiscalYearQuarter(1, a), Q2: l.getFiscalYearQuarter(2, a), Q3: l.getFiscalYearQuarter(3, a), Q4: l.getFiscalYearQuarter(4, a) };
}
};
function z(e, t, a, s, r, n, y, d) {
var u = typeof e == "function" ? e.options : e;
return t && (u.render = t, u.staticRenderFns = a, u._compiled = !0), u._scopeId = "data-v-" + n, {
exports: e,
options: u
};
}
const q = {
name: "NepaliDatepicker",
props: {
value: {
type: String,
default: ""
},
yearSelect: {
type: Boolean,
default: !0
},
monthSelect: {
type: Boolean,
default: !0
},
classValue: {
type: String,
default: ""
},
placeholder: {
type: String,
default: ""
}
},
data() {
return {
MONTH_EN: M,
WEEK_SHORT_EN: p,
date: this.value ? new o(this.value) : new o(),
visible: !1,
formatedValue: this.value,
endDay: null,
previousEndDay: null,
comingEndDay: null,
startMonthValue: null,
yearValue: this.value ? new o(this.value).getYear() : new o().getYear(),
monthValue: this.value ? new o(this.value).getMonth() : new o().getMonth(),
showMonth: !1,
showYear: !1,
startingYear: i[0].year,
endingYear: i.length + i[0].year - 1,
currentYearPage: 0,
YEARS_PER_PAGE: 10,
date_id: this.generateRandomId()
};
},
computed: {
modelValue: {
get() {
return this.value;
}
},
prevDays() {
return this.date.year == this.startingYear && this.date.month == 0 ? [] : (i.forEach((e) => {
let t = this.date.year, a = this.date.month - 1;
this.days[0].month == 0 && (t = t - 1, a = 11), e.year === t && e.days.forEach((s, r) => {
r === a && (this.previousEndDay = s);
});
}), Array(this.previousEndDay).fill(null).map(
(e, t) => new o(this.date.year, this.date.month - 1, t + 1)
).slice(-(this.remainingStartDays ? this.remainingStartDays : 0)));
},
days() {
return i.forEach((e) => {
e.year === this.date.year && e.days.forEach((t, a) => {
a === this.date.month && (this.endDay = t);
});
}), Array(this.endDay).fill(null).map(
(e, t) => new o(this.date.year, this.date.month, t + 1)
);
},
comingDays() {
return this.date.year == this.endingYear && this.date.month == 11 ? [] : (i.forEach((e) => {
let t = this.date.year, a = this.date.month + 1;
this.days[0].month == 11 && (t = t + 1, a = 0), e.year === t && e.days.forEach((s, r) => {
r === a && (this.comingEndDay = s);
});
}), Array(this.comingEndDay).fill(null).map(
(e, t) => new o(this.date.year, this.date.month + 1, t + 1)
).slice(0, this.remainingEndDays));
},
remainingStartDays() {
const e = new o(
this.yearValue,
this.monthValue,
1
);
return p.forEach((t, a) => {
e.format("DDD") === "Su" ? this.startMonthValue = 7 : e.format("DDD") === t && (this.startMonthValue = a);
}), this.startMonthValue;
},
remainingEndDays() {
return 42 - this.days.length - (this.remainingStartDays ? this.remainingStartDays : 0);
},
currentPageYears() {
const e = i.map((a) => a.year), t = this.currentYearPage * this.YEARS_PER_PAGE;
return e.slice(t, t + this.YEARS_PER_PAGE);
},
maxYearPages() {
return Math.ceil(i.length / this.YEARS_PER_PAGE);
}
},
watch: {
value(e) {
this.formatedValue = e, this.yearValue = e ? new o(e).getYear() : new o().getYear(), this.monthValue = e ? new o(e).getMonth() : new o().getMonth(), this.date = e ? new o(e) : new o();
}
},
methods: {
generateRandomId() {
return this.random(3) + this.random(3) + this.random(3);
},
random(e) {
let t = "";
const a = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", s = a.length;
let r = 0;
for (; r < e; )
t += a.charAt(
Math.floor(Math.random() * s)
), r += 1;
return t;
},
toggleYear() {
if (this.showYear = !this.showYear, this.showMonth = !1, this.showYear) {
const e = this.date.year, t = i.findIndex(
(a) => a.year === e
);
this.currentYearPage = Math.floor(t / this.YEARS_PER_PAGE);
}
},
toggleCalendar(e, t) {
e ? this.visible = !0 : t ? this.visible = !1 : this.visible = !this.visible, this.visible ? document.addEventListener("click", this.handleClickOutside) : (document.removeEventListener("click", this.handleClickOutside), this.reset());
},
toggleMonth() {
this.showMonth = !this.showMonth, this.showYear = !1;
},
next() {
let e = this.date.month + 1, t = this.date.year;
e > 11 && (t++, e = 0), t + 1 < this.startingYear || t > this.endingYear || (this.setMonthAndYear(e, t), this.date = new o(t, e, 1));
},
nextYear() {
if (this.showYear)
this.currentYearPage < this.maxYearPages - 1 && this.currentYearPage++;
else {
let e = this.date.month, t = this.date.year + 1;
t < this.startingYear || t > this.endingYear || (this.setMonthAndYear(e, t), this.date = new o(t, e, 1));
}
},
prev() {
let e = this.date.month - 1, t = this.date.year;
e < 0 && (t--, e = 11), t < this.startingYear || t > this.endingYear || (this.setMonthAndYear(e, t), this.date = new o(t, e, 1));
},
prevYear() {
if (this.showYear)
this.currentYearPage > 0 && this.currentYearPage--;
else {
let e = this.date.month, t = this.date.year - 1;
t < this.startingYear || t > this.endingYear || (this.setMonthAndYear(e, t), this.date = new o(t, e, 1));
}
},
activeDay(e) {
return this.modelValue ? new o(this.modelValue).getTime() === e.getTime() : !1;
},
activeMonth(e) {
return this.date.month == e;
},
activeYear(e) {
return this.date.year == e;
},
checkToday(e) {
const t = new o();
return e.day === t.day && e.year === t.year && e.month === t.month;
},
setMonthAndYear(e, t) {
this.monthValue = e, this.yearValue = t;
},
selectMonth(e) {
this.monthValue = e, this.date.setMonth(e), this.showMonth = !1;
},
selectYear(e) {
this.yearValue = e, this.date.setYear(e), this.showYear = !1, this.monthSelect && (this.showMonth = !0);
},
select(e, t) {
this.date = e, this.formatedValue = this.date.format("YYYY-MM-DD"), this.$emit("input", this.formatedValue), this.$emit("onSelect", this.formatedValue), t == null && !t && this.toggleCalendar();
},
updateInputtedValue(e) {
/^\d{4}-\d{2}-\d{2}$/.test(this.formatedValue) || (this.formatedValue = this.modelValue);
try {
const t = new o(this.formatedValue);
this.select(t, e);
} catch {
this.formatedValue = this.modelValue;
}
},
handleClickOutside(e) {
const t = document.getElementById(
"nepali-calendar-" + this.date_id
), a = document.getElementById(
"nepali-date-input-" + this.date_id
);
if (!t || !a)
return;
const s = t.contains(e.target), r = a.contains(e.target), n = e.target, y = n.classList.contains("calendar_month") || n.classList.contains("calendar__year") || n.closest(".calendar__months") || n.closest(".calendar__years");
!s && !r && !y && (this.visible = !1, this.reset(), this.formatedValue != this.modelValue && this.updateInputtedValue(!0), document.removeEventListener("click", this.handleClickOutside));
},
reset() {
this.showMonth = !1, this.showYear = !1, this.date = this.modelValue ? new o(this.modelValue) : new o();
},
resetClear() {
this.showMonth = !1, this.showYear = !1, this.date = new o(), this.$emit("input", ""), this.$emit("onSelect", ""), this.toggleCalendar(!1, !0);
}
},
beforeDestroy() {
document.removeEventListener("click", this.handleClickOutside);
}
};
var J = function() {
var t = this, a = t._self._c;
return a("div", { key: t.date_id, staticClass: "nepali-datepicker", class: this.classValue }, [a("div", { staticClass: "calendar-input-div", class: t.modelValue ? "calendar-input-contain-value" : "" }, [a("input", { directives: [{ name: "model", rawName: "v-model", value: t.formatedValue, expression: "formatedValue" }], staticClass: "calendar-input", attrs: { type: "text", placeholder: t.placeholder, "aria-haspopup": "true", id: "nepali-date-input-" + t.date_id }, domProps: { value: t.formatedValue }, on: { click: function(s) {
return t.toggleCalendar(!0);
}, keyup: function(s) {
return !s.type.indexOf("key") && t._k(s.keyCode, "enter", 13, s.key, "Enter") ? null : t.updateInputtedValue();
}, input: function(s) {
s.target.composing || (t.formatedValue = s.target.value);
} } }), a("div", { staticClass: "calendar-input-icon calender-icon", on: { click: function(s) {
return s.stopPropagation(), t.toggleCalendar(!0);
} } }, [t.visible && t.modelValue ? t._e() : a("svg", { attrs: { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 1024 1024", width: "1em", height: "1em" } }, [a("path", { attrs: { d: "M940.218 107.055H730.764v-60.51H665.6v60.51H363.055v-60.51H297.89v60.51H83.78c-18.617 0-32.581 13.963-32.581 32.581v805.237c0 18.618 13.964 32.582 32.582 32.582h861.09c18.619 0 32.583-13.964 32.583-32.582V139.636c-4.655-18.618-18.619-32.581-37.237-32.581zm-642.327 65.163v60.51h65.164v-60.51h307.2v60.51h65.163v-60.51h176.873v204.8H116.364v-204.8H297.89zM116.364 912.291V442.18H912.29v470.11H116.364z" } })])]), t.modelValue ? a("div", { staticClass: "calendar-input-icon", class: t.visible ? "" : "calendar-clear-input", on: { click: function(s) {
return s.stopPropagation(), t.resetClear();
} } }, [a("svg", { attrs: { width: "1em", height: "1em", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg" } }, [a("path", { attrs: { id: "Vector", d: "M18 18L12 12M12 12L6 6M12 12L18 6M12 12L6 18", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" } })])]) : t._e()]), a("transition", { attrs: { name: "calendar-animation" } }, [t.visible ? a("div", { class: ["calendar", { show: t.visible }], staticStyle: { "user-select": "none" }, attrs: { id: "nepali-calendar-" + t.date_id } }, [a("div", { staticClass: "calendar__body" }, [a("div", { staticClass: "calendar__head" }, [a("div", [a("button", { staticClass: "calendar__toggle_button", on: { click: function(s) {
return t.prevYear();
} } }, [a("i", { staticClass: "calendar-icon-double-left" })]), !t.showMonth && !t.showYear ? a("button", { staticClass: "calendar__toggle_button", on: { click: function(s) {
return t.prev();
} } }, [a("i", { staticClass: "calendar-icon-left" })]) : t._e()]), a("div", { staticClass: "calendar__header_label" }, [t.monthSelect ? t._e() : a("a", [t._v(t._s(t.date.format("MMMM")))]), !t.showMonth && !t.showYear && t.monthSelect ? a("a", { staticClass: "calendar__header_selector", on: { click: function(s) {
return s.stopPropagation(), t.toggleMonth.apply(null, arguments);
} } }, [t._v(t._s(t.date.format("MMMM")))]) : t._e(), t.yearSelect ? t._e() : a("a", [t._v(t._s(t.date.format("YYYY")))]), !t.showYear && t.yearSelect ? a("a", { staticClass: "calendar__header_selector", on: { click: function(s) {
return s.stopPropagation(), t.toggleYear.apply(null, arguments);
} } }, [t._v(t._s(t.date.format("YYYY")))]) : t._e(), t.showYear && t.yearSelect ? a("a", [t._v(" " + t._s(t.currentPageYears[0]) + " ~ " + t._s(t.currentPageYears[t.currentPageYears.length - 1]))]) : t._e()]), a("div", [!t.showMonth && !t.showYear ? a("button", { staticClass: "calendar__toggle_button", on: { click: function(s) {
return t.next();
} } }, [a("i", { staticClass: "calendar-icon-right" })]) : t._e(), a("button", { staticClass: "calendar__toggle_button", on: { click: function(s) {
return t.nextYear();
} } }, [a("i", { staticClass: "calendar-icon-double-right" })])])]), a("div", { staticClass: "calendar__container" }, [!t.showMonth && !t.showYear ? a("div", [a("div", { staticClass: "calendar__weeks" }, t._l(t.WEEK_SHORT_EN, function(s, r) {
return a("div", { key: r, staticClass: "calendar__weekday" }, [t._v(" " + t._s(s) + " ")]);
}), 0), a("div", { staticClass: "calendar__days" }, [t._l(t.remainingStartDays, function(s) {
return t.date.year == t.startingYear && t.date.month == 0 ? a("div", { key: s, staticClass: "calendar__day_spacer" }) : t._e();
}), t._l(t.prevDays, function(s, r) {
return t.remainingStartDays ? a("div", { key: r + "-prev", staticClass: "calendar__day not_current_month", attrs: { title: `${s.year}-${s.month + 1}-${s.day}` }, on: { click: function(n) {
return t.select(s);
} } }, [a("span", [t._v(t._s(s.day))])]) : t._e();
}), t._l(t.days, function(s, r) {
return a("div", { key: r + "-current", staticClass: "calendar__day", class: { selected: t.activeDay(s), today: t.checkToday(s) }, attrs: { title: `${s.year}-${s.month + 1}-${s.day}` }, on: { click: function(n) {
return t.select(s);
} } }, [a("span", [t._v(t._s(s.day))])]);
}), t._l(t.comingDays, function(s, r) {
return t.remainingStartDays ? a("div", { key: r + "-new", staticClass: "calendar__day not_current_month", attrs: { title: `${s.year}-${s.month + 1}-${s.day}` }, on: { click: function(n) {
return t.select(s);
} } }, [a("span", [t._v(t._s(s.day))])]) : t._e();
}), t._l(t.remainingEndDays, function(s) {
return t.date.year == t.endingYear && t.date.month == 11 ? a("div", { key: s, staticClass: "calendar__day_spacer" }) : t._e();
})], 2)]) : t._e(), t.showMonth ? a("div", { staticClass: "calendar__months", on: { click: function(s) {
s.stopPropagation();
} } }, t._l(t.MONTH_EN, function(s, r) {
return a("div", { staticClass: "calendar_month", class: { selected: t.activeMonth(r) }, on: { click: function(n) {
return t.selectMonth(r);
} } }, [t._v(" " + t._s(s) + " ")]);
}), 0) : t._e(), t.showYear ? a("div", { staticClass: "calendar__years", on: { click: function(s) {
s.stopPropagation();
} } }, t._l(t.currentPageYears, function(s) {
return a("div", { staticClass: "calendar__year", class: { selected: t.activeYear(s) }, on: { click: function(r) {
return t.selectYear(s);
} } }, [t._v(" " + t._s(s) + " ")]);
}), 0) : t._e()])])]) : t._e()])], 1);
}, U = [], X = /* @__PURE__ */ z(
q,
J,
U,
!1,
null,
"7d17e911"
);
const tt = X.exports;
export {
tt as NepaliDatePicker
};