
class SmartDateDayPart extends AbstractSmartDateNumericPart
{
    constructor()
    {
        super(SmartDateFormat.DAY_PLACEHOLDER, 2);
        this.maximalValue = SmartDateDayPart.MAXIMAL_VALUE;
    }
    
    resetState()
    {
        super.resetState();
        this.maximalValue = SmartDateDayPart.MAXIMAL_VALUE;
    }
    
    setMaximalValue(value)
    {
        if (value != value /* isNaN */ || value < SmartDateDayPart.MAXIMAL_VALUE_LOW_LIMIT || SmartDateDayPart.MAXIMAL_VALUE_HIGH_LIMIT < value) {
            return;
        }
        
        this.maximalValue = value;
        
        if (this._numericValue <= this.maximalValue) {
            return;
        }
        
        this._numericValue = this.maximalValue;
        this._defineCleanValue();
    }
    
    resetMaximalValue()
    {
        this.maximalValue = SmartDateDayPart.MAXIMAL_VALUE;
    }
    
    /**
     * @param {Date} date
     * @returns {String}
     */
    formatDate(date)
    {
        return this.formatValue(date.getDate());
    }

    /**
     * @param {SmartDateCheckState} state
     */
    parse(state)
    {
        this._parsedValue = this.scanStringNumber(state);
        this._numericValue = this.calculateNumericValue(this._parsedValue, this.maximalValue);
        
        this._defineParsingState(this.maximalValue, state.isOver());
        this._defineCleanValue();
    }
}

SmartDateDayPart.MAXIMAL_VALUE_LOW_LIMIT = 28;
SmartDateDayPart.MAXIMAL_VALUE_HIGH_LIMIT = 31;

SmartDateDayPart.MAXIMAL_VALUE = SmartDateDayPart.MAXIMAL_VALUE_HIGH_LIMIT;
