@rnwonder/react-date-picker
Version:
A lightweight, customizable, and accessible date picker component for React applications.
174 lines (173 loc) • 5.5 kB
JavaScript
const M = (e) => typeof e == "function" ? e() : e, i = (e, a) => new Intl.NumberFormat(a || "en-US", {
useGrouping: !1
}).format(e), m = (e, a, n) => {
const t = new Date(e, a, n);
return t.setFullYear(e), t;
}, s = (e, a) => String(Math.ceil(e)).padStart(a ?? 2, "0"), D = (e) => e === 0 ? 12 : e === 12 ? 0 : e > 12 ? e - 12 : e, L = (e) => e >= 12 ? "PM" : "AM", x = (e, a) => a === "AM" ? e === 12 ? 0 : e : e === 0 ? 12 : e === 12 ? e : e + 12;
function R() {
const e = /* @__PURE__ */ new Date();
let a = e.getHours();
const n = e.getMinutes(), t = e.getSeconds();
let r = "AM";
return a > 12 && (a -= 12, r = "PM"), a === 12 && (r = "PM"), a === 0 && (a = 12), {
hour: a,
minute: n,
second: t,
meridiem: r
};
}
function E({
startYear: e,
endYear: a,
count: n,
year: t,
yearRange: r,
locale: o
}) {
const c = t || (/* @__PURE__ */ new Date()).getFullYear();
if (!e) {
const l = Math.floor(c / n) * n;
l === c ? e = c - n + 1 : e = l + 1;
}
a || (a = e + n - 1);
const g = [];
let u = e, d = a;
for (let l = e; l <= a; l++) {
if (r != null && r.start && l < (r == null ? void 0 : r.start)) {
g.push(""), u = r == null ? void 0 : r.start;
continue;
}
if (r != null && r.end && l > (r == null ? void 0 : r.end)) {
g.push(""), d = r == null ? void 0 : r.end;
continue;
}
g.push(i(l, o));
}
return {
array: g,
range: `${i(u, o)} - ${i(d, o)}`,
startYear: e,
endYear: a
};
}
const w = (e, a, n = "en-US") => {
const t = h(e);
return a = a.replace(
new RegExp("(?<!~)(?<!n)nn(?!n)", "g"),
t.toLocaleString(n, { minute: "2-digit" }).padStart(2, "0")
).replace(
new RegExp("(?<!~)(?<!n)n(?!n)", "g"),
t.toLocaleString(n, { minute: "numeric" })
).replace(
new RegExp("(?<!~)(?<!s)ss(?!s)", "g"),
t.toLocaleString(n, { second: "2-digit" }).padStart(2, "0")
).replace(
new RegExp("(?<!~)(?<!s)s(?!s)", "g"),
t.toLocaleString(n, { second: "numeric" })
).replace(
new RegExp("(?<!~)(?<!h)hh(?!h)", "g"),
t.toLocaleString(n, { hour: "2-digit", hour12: !0 }).split(" ")[0].padStart(2, "0")
).replace(
new RegExp("(?<!~)(?<!h)h(?!h)", "g"),
t.toLocaleString(n, { hour: "numeric", hour12: !0 })
).replace(
new RegExp("(?<!~)(?<!H)HH(?!H)", "g"),
t.toLocaleString(n, { hour: "2-digit", hour12: !1 }).split(" ")[0].padStart(2, "0")
).replace(
new RegExp("(?<!~)(?<!H)H(?!H)", "g"),
t.toLocaleString(n, { hour: "numeric", hour12: !1 })
).replace(
new RegExp("(?<!~)(?<!a)a(?!a)", "g"),
S(
t.toLocaleString(n, { hour: "numeric", hour12: !0 }).split(" ")[1]
)
).replace(
new RegExp("(?<!~)(?<!y)yyyy(?!y)", "g"),
t.toLocaleString(n, { year: "numeric" })
).replace(
new RegExp("(?<!~)(?<!y)yy(?!y)", "g"),
t.toLocaleString(n, { year: "2-digit" })
).replace(
new RegExp("(?<!~)(?<!m)m(?!m)", "g"),
t.toLocaleString(n, { month: "numeric" })
).replace(
new RegExp("(?<!~)(?<!m)mm(?!m)", "g"),
t.toLocaleString(n, { month: "2-digit" })
).replace(
new RegExp("(?<!~)(?<!d)dd(?!d)", "g"),
t.toLocaleString(n, { day: "2-digit" })
).replace(
new RegExp("(?<!~)(?<!d)d(?!d)", "g"),
t.toLocaleString(n, { day: "numeric" })
).replace(
new RegExp("(?<!~)(?<!D)DDD(?!D)", "g"),
p(t.toLocaleString(n, { weekday: "long" }))
).replace(
new RegExp("(?<!~)(?<!D)DD(?!D)", "g"),
p(t.toLocaleString(n, { weekday: "short" }))
).replace(
new RegExp("(?<!~)(?<!D)D(?!D)", "g"),
p(t.toLocaleString(n, { weekday: "narrow" }))
).replace(
new RegExp("(?<!~)(?<!M)MMM(?!M)", "g"),
t.toLocaleString(n, { month: "long" })
).replace(
new RegExp("(?<!~)(?<!M)MM(?!M)", "g"),
t.toLocaleString(n, { month: "short" })
).replace(
new RegExp("(?<!~)(?<!M)M(?!M)", "g"),
t.toLocaleString(n, { month: "narrow" })
).replace(/~y/g, "y").replace(/~m/g, "m").replace(/~M/g, "M").replace(/~d/g, "d").replace(/~D/g, "D").replace(/~H/g, "H").replace(/~n/g, "n").replace(/~s/g, "s").replace(/~a/g, "a").replace(/~h/g, "h"), a;
}, h = (e) => {
let a;
return typeof e == "string" || typeof e == "number" ? a = new Date(e) : e instanceof Date ? a = e : a = m(
e.year || 2023,
!e.month && e.month !== 0 ? 1 : e.month,
e.day
), a;
}, f = (e) => {
const a = e.getFullYear(), n = e.getMonth(), t = e.getDate();
return {
year: a,
month: n,
day: t
};
}, v = (e) => {
const a = /* @__PURE__ */ new Date(), n = (e == null ? void 0 : e.year) ?? a.getFullYear(), t = (e == null ? void 0 : e.month) === 0 ? 0 : (e == null ? void 0 : e.month) ?? a.getMonth(), r = (e == null ? void 0 : e.day) ?? a.getDate(), o = new Date(n, t, r);
return o.setFullYear(n), o;
}, H = (e, a) => {
const { localeOptions: n, locale: t, format: r } = a || {}, o = h(e);
return y({
date: o,
option: n || {
month: "short",
day: "numeric",
year: "numeric"
},
locale: t,
format: r
});
}, y = ({
format: e,
option: a,
date: n,
locale: t
}) => e ? w(n, e, t) : n.toLocaleDateString(t ?? "en-US", a), p = (e) => e.startsWith("M") ? "~" + e : e, S = (e) => e === "AM" ? "A~M" : e === "PM" ? "P~M" : e, Y = (e) => e === 0 ? 12 : e !== void 0 ? s(e) : "", F = (e) => e !== void 0 ? s(e) : "";
export {
f as A,
y as D,
R as F,
x as H,
F as I,
M as L,
Y as P,
m as S,
s as a,
E as b,
D as d,
i as g,
h,
v as k,
H as v,
L as w
};