You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
13 KiB
JavaScript

class AbstractSmartDatePart{constructor(a,b){this._state=AbstractSmartDatePart.STATE_NONE,this._cleanedValue="",this._parsedValue="",this._scanned="",this._placeholder=a,this._static=b}state(){return this._state}isNoState(){return this._state===AbstractSmartDatePart.STATE_NONE}isIncomplete(){return this._state===AbstractSmartDatePart.STATE_INCOMPLETE}isComplete(){return this._state===AbstractSmartDatePart.STATE_COMPLETE}resetState(){this._state=AbstractSmartDatePart.STATE_NONE}cleanedValue(){return this._cleanedValue}parsedValue(){return this._parsedValue}placeHolder(){return this._placeholder}isStatic(){return this._static}_isNumericSymbol(a){return"0"<=a&&"9">=a}check(a){return!1}}AbstractSmartDatePart.STATE_NONE=0,AbstractSmartDatePart.STATE_INCOMPLETE=1,AbstractSmartDatePart.STATE_COMPLETE=2;class SmartDateStaticPart extends AbstractSmartDatePart{constructor(a){super(a,!0),this._cleanedValue=a}parse(a){let b=a.value(),c=a.valueIndex();for(;c<b.length&&!this._isNumericSymbol(b[c]);)c++;return this._parsedValue=b.substring(a.valueIndex(),c),this._state=AbstractSmartDatePart.STATE_COMPLETE,a.setValueIndex(c),!0}}class AbstractSmartDateNumericPart extends AbstractSmartDatePart{constructor(a,b){super(a,!1),this._numericValue=0,this._size=b}numericValue(){return this._numericValue}formatDate(a){return""}formatValue(a){let b=this._correctValue(a)+"";return"0"==b?b:b.length>this._size?b.substring(0,this._size):b.length<this._size?b.padStart(this._size,"0"):b}_correctValue(a){return Math.round(a)}scanStringNumber(a){let b=a.valueIndex(),c=a.value();for(;b<c.length&&this._isNumericSymbol(c[b]);)b++;let d=c.substring(a.valueIndex(),b);return a.setValueIndex(b),d}calculateNumericValue(a,b){for(var c=0,d=0,e=0;c<a.length&&0===a[c];)c++;for(d=c;d<a.length&&e<b;)e=10*e+ +a[d],d++;return e>b&&d--,+a.substring(c,d)}scanValue(a,b){let c=a.valueIndex(),d=a.value(),e=0;for(;c<d.length&&this._isNumericSymbol(d[c])&&e<b;)e=10*e+ +d[c],c++;e>b&&c--;let f=d.substring(a.valueIndex(),c);return a.setValueIndex(c),f}_defineParsingState(a,b){return 0<this._numericValue&&(this._parsedValue.length>=this._size||!b)?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):10*this._numericValue>a?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):void(this._state=AbstractSmartDatePart.STATE_INCOMPLETE)}_defineCleanValue(){return this._cleanedValue="",this.isNoState()?void 0:this.isComplete()?void(this._cleanedValue=this.formatValue(this._numericValue)):void(0<this._parsedValue.length&&(this._cleanedValue=this._numericValue+""))}}class SmartDateDayPart extends AbstractSmartDateNumericPart{constructor(){super(SmartDateFormat.DAY_PLACEHOLDER,2),this.maximalValue=SmartDateDayPart.MAXIMAL_VALUE}resetState(){super.resetState(),this.maximalValue=SmartDateDayPart.MAXIMAL_VALUE}setMaximalValue(a){a!=a||a<SmartDateDayPart.MAXIMAL_VALUE_LOW_LIMIT||SmartDateDayPart.MAXIMAL_VALUE_HIGH_LIMIT<a||(this.maximalValue=a,this._numericValue<=this.maximalValue||(this._numericValue=this.maximalValue,this._defineCleanValue()))}resetMaximalValue(){this.maximalValue=SmartDateDayPart.MAXIMAL_VALUE}formatDate(a){return this.formatValue(a.getDate())}parse(a){this._parsedValue=this.scanStringNumber(a),this._numericValue=this.calculateNumericValue(this._parsedValue,this.maximalValue),this._defineParsingState(this.maximalValue,a.isOver()),this._defineCleanValue()}}SmartDateDayPart.MAXIMAL_VALUE_LOW_LIMIT=28,SmartDateDayPart.MAXIMAL_VALUE_HIGH_LIMIT=31,SmartDateDayPart.MAXIMAL_VALUE=SmartDateDayPart.MAXIMAL_VALUE_HIGH_LIMIT;class SmartDateMonthPart extends AbstractSmartDateNumericPart{constructor(){super(SmartDateFormat.MONTH_PLACEHOLDER,2)}formatDate(a){return this.formatValue(a.getMonth()+1)}parse(a){this._parsedValue=this.scanStringNumber(a),this._numericValue=this.calculateNumericValue(this._parsedValue,SmartDateMonthPart.MAXIMAL_VALUE),this._defineParsingState(SmartDateMonthPart.MAXIMAL_VALUE,a.isOver()),this._defineCleanValue()}}SmartDateMonthPart.MAXIMAL_VALUE=12;class SmartDateYearPart extends AbstractSmartDateNumericPart{constructor(){super(SmartDateFormat.YEAR_PLACEHOLD