UNPKG

ayongui

Version:
96 lines (95 loc) 3.18 kB
const d = (e, t) => new Date(e, t + 1, 0).getDate(); function u(e) { var t = new Date(e), a = /* @__PURE__ */ new Date(); return t.setHours(0, 0, 0, 0), a.setHours(0, 0, 0, 0), t.getTime() === a.getTime(); } const f = ({ year: e, month: t, start: a, end: s, type: i, cFormat: c }) => { const l = []; if (i === "prev") { if (a === s) return []; const n = d(e, t - 1); for (let r = n - s + 2; r <= n; r++) l.push({ // date: `${month === 0 ? year - 1 : year}-${(month + 1) < 10 ? month === 0 ? 12 : `0${month}` : month}-${i < 10 ? `0${i}` : i}`, date: o(new Date(e, t - 1, r), c), comprehensive: new Date(e, t - 1, r), comprehensiveStr: o(new Date(e, t - 1, r), "{y}-{m}-{d}"), monthSortMode: 1, isSelected: !1, isRangeSelected: !1, isToday: u(new Date(e, t - 1, r)) }); } else if (i === "rear") for (let n = a; n <= s; n++) l.push({ // date: `${month === 11 ? year + 1 : year}-${(month + 1) < 9 ? `0${month + 2}` : month + 2 <= 12 ? month + 2 : (month + 2) % 12 < 10 ? `0${(month + 2) % 12}` : (month + 2) % 12}-${i < 10 ? `0${i}` : i}`, date: o(new Date(e, t + 1, n), c), comprehensive: new Date(e, t + 1, n), comprehensiveStr: o(new Date(e, t + 1, n), "{y}-{m}-{d}"), monthSortMode: 2, isSelected: !1, isRangeSelected: !1, isToday: u(new Date(e, t + 1, n)) }); else for (let n = a; n <= s; n++) l.push({ // date: `${year}-${(month + 1) < 10 ? `0${month + 1}` : month + 1}-${i < 10 ? `0${i}` : i}`, date: o(new Date(e, t, n), c), comprehensive: new Date(e, t, n), comprehensiveStr: o(new Date(e, t, n), "{y}-{m}-{d}"), monthSortMode: 0, isSelected: !1, isRangeSelected: !1, isToday: u(new Date(e, t, n)) }); return l; }, D = (e = [1970, 2099]) => { const t = [], a = []; for (let s = e[0]; s <= e[1]; s++) t.push({ label: `${s}年`, value: s }); for (let s = 0; s <= 11; s++) a.push({ label: `${s + 1}月`, value: s + 1 }); return { years: t, months: a }; }; function o(e, t) { if (arguments.length === 0 || !e) return null; const a = t || "{y}-{m}-{d}"; let s; typeof e == "object" ? s = e : (typeof e == "string" && (/^[0-9]+$/.test(e) ? e = parseInt(e) : e = e.replace(new RegExp(/-/gm), "/")), typeof e == "number" && e.toString().length === 10 && (e = e * 1e3), s = new Date(e)); const i = { y: s.getFullYear(), m: s.getMonth() + 1, d: s.getDate(), h: s.getHours(), i: s.getMinutes(), s: s.getSeconds(), a: s.getDay() }; return a.replace(/{([ymdhisa])+}/g, (l, n) => { const r = i[n]; return n === "a" ? ["日", "一", "二", "三", "四", "五", "六"][r] : r.toString().padStart(2, "0"); }); } function p(e) { const t = new Date(e); return Object.prototype.toString.call(t) === "[object Date]" && !isNaN(t.getTime()) && e === t.toISOString().split("T")[0]; } export { d as getDaysInMonth, f as handleCrateDate, D as handleCreateDatePicker, p as isValidDate, o as parseTime };