UNPKG

@rnwonder/react-date-picker

Version:

A lightweight, customizable, and accessible date picker component for React applications.

69 lines (68 loc) 2.84 kB
import { h as l, D as T, A as h } from "./format-CMbjATj9-B6oamtiF.js"; var c = Object.defineProperty, C = (i, t, s) => t in i ? c(i, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : i[t] = s, U = (i, t, s) => (C(i, t + "", s), s); class d { constructor(t) { U(this, "date"), this.date = t; } static set(t) { const s = l(t); return new d(s); } plus(t) { const { day: s = 0, month: r = 0, year: n = 0, hour: a = 0, minute: o = 0, second: u = 0 } = t, e = new Date(this.date.getTime()); return n && e.setUTCFullYear(e.getUTCFullYear() + n), r && e.setUTCMonth(e.getUTCMonth() + r), s && e.setUTCDate(e.getUTCDate() + s), a && e.setUTCHours(e.getUTCHours() + a), o && e.setUTCMinutes(e.getUTCMinutes() + o), u && e.setUTCSeconds(e.getUTCSeconds() + u), new d(e); } minus(t) { const { day: s = 0, month: r = 0, year: n = 0, hour: a = 0, minute: o = 0, second: u = 0 } = t, e = new Date(this.date.getTime()); return n && e.setUTCFullYear(e.getUTCFullYear() - n), r && e.setUTCMonth(e.getUTCMonth() - r), s && e.setUTCDate(e.getUTCDate() - s), a && e.setUTCHours(e.getUTCHours() - a), o && e.setUTCMinutes(e.getUTCMinutes() - o), u && e.setUTCSeconds(e.getUTCSeconds() - u), new d(e); } diffNow(t) { return this.diff(new d(/* @__PURE__ */ new Date()), t); } diff(t, s = ["milliseconds"]) { const r = this.date.getTime() - t.date.getTime(), n = {}, a = Math.abs(r); return s.includes("milliseconds") && (n.milliseconds = a), s.includes("seconds") && (n.seconds = a / 1e3), s.includes("minutes") && (n.minutes = a / (1e3 * 60)), s.includes("hours") && (n.hours = a / (1e3 * 60 * 60)), s.includes("days") && (n.days = a / (1e3 * 60 * 60 * 24)), s.includes("weeks") && (n.weeks = a / (1e3 * 60 * 60 * 24 * 7)), s.includes("months") && (n.months = (this.date.getUTCFullYear() - t.date.getUTCFullYear()) * 12 + (this.date.getUTCMonth() - t.date.getUTCMonth())), s.includes("quarters") && (n.quarters = (n.months ?? (this.date.getUTCFullYear() - t.date.getUTCFullYear()) * 12 + (this.date.getUTCMonth() - t.date.getUTCMonth())) / 3), s.includes("years") && (n.years = (n.months ?? (this.date.getUTCFullYear() - t.date.getUTCFullYear()) * 12 + (this.date.getUTCMonth() - t.date.getUTCMonth())) / 12), n; } toString(t) { const { localeOptions: s, locale: r, format: n } = t || {}; return T({ date: this.date, option: s || { month: "short", day: "numeric", year: "numeric" }, locale: r, format: n }); } toObject() { return h(this.date); } toJSDate() { return this.date; } toMillis() { return this.date.getTime(); } toISO() { return this.date.toISOString(); } } export { d as default };