class SmartDateYearPart extends AbstractSmartDateNumericPart { constructor() { super(SmartDateFormat.YEAR_PLACEHOLDER, 4); } /** * @param {Date} date * @returns {String} */ formatDate(date) { return this.formatValue(date.getFullYear()); } /** * @param {SmartDateCheckState} state * @returns {Boolean} */ parse(state) { this._parsedValue = this.scanStringNumber(state); this._numericValue = Number(this._parsedValue); this._defineParsingState(); if (this._numericValue > SmartDateYearPart.MAXIMAL_VALUE) { this._numericValue = SmartDateYearPart.MAXIMAL_VALUE; } if (this.isComplete() && this._numericValue < SmartDateYearPart.MINIMAL_VALUE) { this._numericValue = SmartDateYearPart.MINIMAL_VALUE; } this._defineCleanValue(); } _defineParsingState() { if (this._numericValue > 0 && this._parsedValue.length >= this._size) { this._state = AbstractSmartDatePart.STATE_COMPLETE; return; } this._state = AbstractSmartDatePart.STATE_INCOMPLETE; } _defineCleanValue() { if (this._numericValue > 0) { this._cleanedValue = String(this._numericValue); } else { this._cleanedValue = ''; } } } SmartDateYearPart.MINIMAL_VALUE = 1000; SmartDateYearPart.MAXIMAL_VALUE = 9999;