UNPKG

@dialpad/dialtone

Version:

Dialpad's Dialtone design system monorepo

49 lines (48 loc) 2 kB
import "./datepicker-constants.js"; import { addDays as e, addMonths as t, endOfMonth as n, getDate as r, getDay as i, getMonth as a, isEqual as o, startOfDay as s, startOfMonth as c, startOfWeek as l, subMonths as u } from "date-fns"; //#region components/datepicker/utils.js var d = (e) => e ? new Date(e) : /* @__PURE__ */ new Date(), f = (t, n, r, i = null, o = null) => { let c = d(JSON.parse(JSON.stringify(t))), l = i ? s(i) : null, u = o ? s(o) : null, f = []; for (let t = 0; t < 7; t++) { let i = e(c, t), o = a(i) !== n, d = o || l && s(i) < l || u && s(i) > u; f.push({ text: i.getDate(), value: i, currentMonth: !o, disabled: !!d, isFirstDayOfMonth: i.getDate() === 1 && !o, selected: r ? i.getDate() === r && !d : !1 }); } return f; }, p = (e, t) => !e || !t ? !1 : o(e, t), m = (t, n, r, i = null, a = null, o = 0) => { let s = [], c = d(new Date(n, t)), u = d(new Date(n, t + 1, 0)), m = l(c, { weekStartsOn: o }), h = (n) => { let o = f(n, t, r, i, a); s.push({ days: o }), s[s.length - 1].days.some((e) => p(e.value, u)) || h(e(n, 7)); }; return h(m), s; }, h = (e, t) => { let n = [ 1, 2, 3, 4, 5, 6, 7 ].map((t) => new Intl.DateTimeFormat(e, { weekday: "short", timeZone: "UTC" }).format(/* @__PURE__ */ new Date(`2017-01-0${t}T00:00:00+00:00`)).slice(0, 2)), r = n.slice(0, t), i = n.slice(t + 1, n.length); return [n[t]].concat(...i, ...r); }, g = (e, t, n) => new Intl.DateTimeFormat(n, { month: t }).format(new Date(2e3, e, 1)), _ = (e, t, n) => new Intl.DateTimeFormat(n, { dateStyle: t }).format(new Date(e)), v = (n) => { let a = new Date(n), o = i(a), s = c(t(a, 1)); return r(e(s, (o - i(s) + 7) % 7)); }, y = (t) => { let a = new Date(t), o = i(a), s = n(u(a, 1)); for (; i(s) !== o;) s = e(s, -1); return r(s); }; //#endregion export { v as calculateNextFocusDate, y as calculatePrevFocusDate, _ as formatDate, g as formatMonth, m as getCalendarDays, h as getWeekDayNames }; //# sourceMappingURL=utils.js.map