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.
63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
|
|
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;
|