dk-plus
Version:
45 lines (44 loc) • 1.78 kB
JavaScript
const D = (t) => String(t).padStart(2, "0"), F = (t) => {
const e = t.getFullYear(), n = t.getMonth() + 1, o = t.getDate();
return `${e}-${D(n)}-${D(o)}`;
}, w = (t) => {
if (!t)
return null;
const e = /^\s*(\d{4})-(\d{2})-(\d{2})\s*$/.exec(t);
if (!e)
return null;
const n = Number(e[1]), o = Number(e[2]), r = Number(e[3]);
if ([n, o, r].some((u) => Number.isNaN(u)) || o < 1 || o > 12 || r < 1 || r > 31)
return null;
const s = new Date(n, o - 1, r);
return s.getFullYear() !== n || s.getMonth() !== o - 1 || s.getDate() !== r ? null : s;
}, y = (t) => new Date(t.getFullYear(), t.getMonth(), t.getDate()), i = (t, e) => t.getFullYear() === e.getFullYear() && t.getMonth() === e.getMonth() && t.getDate() === e.getDate(), Y = (t, e) => {
const n = t.getFullYear(), o = t.getMonth() + e, r = t.getDate(), s = new Date(n, o, 1), u = new Date(s.getFullYear(), s.getMonth() + 1, 0).getDate();
return s.setDate(Math.min(r, u)), s;
}, p = (t, e, n, o, r, s) => {
const f = ((new Date(t, e, 1).getDay() - o) % 7 + 7) % 7, c = new Date(t, e, 1 - f), d = y(new Date()), g = [];
for (let l = 0; l < 42; l++) {
const a = new Date(c.getFullYear(), c.getMonth(), c.getDate() + l), h = a.getMonth() === e, m = typeof s == "function" ? !!s(a) : !1;
g.push({
date: a,
text: a.getDate(),
isCurrentMonth: h,
isToday: i(a, d),
isSelected: !!n && i(a, n),
isDisabled: r || m
});
}
return g;
}, N = (t) => {
const e = ["\u65E5", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D"], n = (t % 7 + 7) % 7;
return e.slice(n).concat(e.slice(0, n));
};
export {
Y as addMonths,
p as buildMonthCells,
N as buildWeekdays,
F as formatDate,
i as isSameDay,
w as parseDate,
y as startOfDay
};