UNPKG

@progress/kendo-vue-dateinputs

Version:
89 lines (88 loc) 2.92 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import { isEqual as d } from "@progress/kendo-date-math"; import "@progress/kendo-vue-intl"; import { MIDNIGHT_DATE as p } from "../../utils.mjs"; import { setMinutes as r, range as x } from "../utils.mjs"; const m = 60, I = (n) => (t) => t % n, c = I(m), f = (n, t) => (i) => c(n + i * t), M = (n, t) => c(m + n - t), u = (n) => (t, i) => !i || t.getHours() === i.getHours() ? t : r(t, n), l = u(0), L = u(m - 1); class T { constructor(t) { this.intl = t, this.insertUndividedMax = !1; } apply(t, i) { return r(t, i.getMinutes()); } configure(t) { const { insertUndividedMax: i = this.insertUndividedMax, min: s = this.min, max: h = this.max, part: e, step: o = this.step } = t; this.insertUndividedMax = i, this.toListItem = (g) => { const a = r(p, g); return { text: this.intl.formatDate(a, e.pattern), value: a }; }, this.min = s, this.max = h, this.step = o; } data(t) { const [i] = this.range(t), s = f(i, this.step), h = (o) => this.toListItem(s(o)), e = x(0, this.countFromMin(t)).map(h); return this.addLast(e), t && this.addMissing(e, t), e; } isRangeChanged(t, i) { return !d(this.min, t) || !d(this.max, i); } limitRange(t, i, s) { return [l(t, s), L(i, s)]; } total(t) { const i = this.insertUndividedMax && this.isLastMissing(t) ? 1 : 0, s = this.isMissing(t) ? 1 : 0; return this.countFromMin(t) + s + i; } selectedIndex(t) { return Math.ceil(this.divideByStep(t)); } valueInList(t) { return t ? this.insertUndividedMax && this.lastMinute(t) === t.getMinutes() || !this.isMissing(t) : !0; } addLast(t, i) { return this.insertUndividedMax && this.isLastMissing(i) && t.push(this.toListItem(this.lastMinute(i))), t; } addMissing(t, i) { if (this.valueInList(i)) return t; const s = this.toListItem(i.getMinutes()); return t.splice(this.selectedIndex(i), 0, s), t; } countFromMin(t) { const [i, s] = this.range(t); return Math.floor(M(s, i) / this.step) + 1; } isMissing(t) { return t ? this.selectedIndex(t) !== this.divideByStep(t) : !1; } isLastMissing(t) { return this.isMissing(r(this.max, this.lastMinute(t))); } divideByStep(t) { return M(t.getMinutes(), this.min.getMinutes()) / this.step; } lastMinute(t) { return this.range(t)[1]; } range(t) { const [i, s] = this.limitRange(this.min, this.max, t); return [i.getMinutes(), s.getMinutes()]; } } export { T as MinutesService };