UNPKG

@progress/kendo-react-dateinputs

Version:

React DateInput is a perfect input component for handling quick and efficient date values. KendoReact Date Inputs package

9 lines (8 loc) 2.58 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@progress/kendo-date-math"),l=require("../../utils.js"),r=require("../utils.js"),c=60,S=n=>t=>t%n,g=S(c),x=(n,t)=>s=>g(n+s*t),m=(n,t)=>g(c+n-t),u=n=>(t,s)=>!s||t.getMinutes()===s.getMinutes()&&t.getHours()===s.getHours()?t:r.setSeconds(t,n),p=u(0),I=u(c-1);class L{constructor(t){this.intl=t,this.toListItem=null,this.min=null,this.max=null,this.step=0,this.insertUndividedMax=!1}apply(t,s){return r.setSeconds(t,s.getSeconds())}configure(t){const{insertUndividedMax:s=this.insertUndividedMax,min:i=this.min,max:o=this.max,part:e,step:h=this.step}=t;this.insertUndividedMax=s,this.toListItem=M=>{const d=r.setSeconds(l.MIDNIGHT_DATE,M);return{text:this.intl.formatDate(d,e.pattern),value:d}},this.min=i,this.max=o,this.step=h}data(t){const[s]=this.range(t),i=x(s,this.step),o=h=>this.toListItem&&this.toListItem(i(h)),e=r.range(0,this.countFromMin(t)).map(o);return this.addLast(e),t&&this.addMissing(e,t),e}isRangeChanged(t,s){return this.min!==null&&this.max!==null&&(!a.isEqual(this.min,t)||!a.isEqual(this.max,s))}limitRange(t,s,i){return[p(t,i),I(s,i)]}total(t){const s=this.insertUndividedMax&&this.isLastMissing(t)?1:0,i=this.isMissing(t)?1:0;return this.countFromMin(t)+i+s}selectedIndex(t){return Math.ceil(this.divideByStep(t))}valueInList(t){return t?this.insertUndividedMax&&this.lastSecond(t)===t.getSeconds()||!this.isMissing(t):!0}divideByStep(t){return m(t.getSeconds(),this.min.getSeconds())/this.step}addLast(t,s){return this.insertUndividedMax&&this.isLastMissing(s)&&this.toListItem&&t.push(this.toListItem(this.lastSecond(s))),t}addMissing(t,s){if(this.valueInList(s))return t;if(this.toListItem){const i=this.toListItem(s.getSeconds());t.splice(this.selectedIndex(s),0,i)}return t}countFromMin(t){const[s,i]=this.range(t);return Math.floor(m(i,s)/this.step)+1}isMissing(t){return t?this.selectedIndex(t)!==this.divideByStep(t):!1}isLastMissing(t){return this.max!==null&&this.isMissing(r.setSeconds(this.max,this.lastSecond(t)))}lastSecond(t){return this.range(t)[1]}range(t){const[s,i]=this.limitRange(this.min,this.max,t);return[s.getSeconds(),i.getSeconds()]}}exports.SecondsService=L;