TrDateTimeRangeValidator.prototype.validate = function()

in trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js [628:774]


TrDateTimeRangeValidator.prototype.validate  = function(
  value,
  label,
  converter
)
{
  dateTime = value.getTime();
  var facesMessage;
  var isoConverter = this._getISOConverter ();
  //range
  if(this._minValue && this._maxValue)
  {
    try
    {
       // min/maxISODate were introduced in TRINIDAD-1920, pre-existing callers may have them null.
       // If so, revert to previous  behavior where we just parse the min/maxValue string, though
       // that may have less information than the ISO version. 
        minDate = (this._minISODate == null) ? 
                    converter.getAsObject (this._minValue).getTime() :
                    isoConverter.getAsObject (this._minISODate).getTime ();

        maxDate = (this._maxISODate == null) ? 
                    converter.getAsObject (this._maxValue).getTime () :
                    isoConverter.getAsObject (this._maxISODate).getTime ();
    }
    catch (e)
    {
      // Make the validator lenient: let the server convert/validate if 
      // client conversion fails
      return value;
    }
    
    if(dateTime >= minDate && dateTime <= maxDate)
    {
      return value;
    }
    else
    {
      var key = "org.apache.myfaces.trinidad.validator.DateTimeRangeValidator.NOT_IN_RANGE";
      if(this._messages && this._messages["range"])
        {
          facesMessage = _createCustomFacesMessage(TrMessageFactory.getSummaryString(key),
                                        this._messages["range"],
                                        label,
                                        ""+converter.getAsString(value),
                                        ""+this._minValue,
                                        ""+this._maxValue);
        }
      else
      {
          facesMessage = _createFacesMessage(key,
                                        label,
                                        ""+converter.getAsString(value),
                                        ""+this._minValue,
                                        ""+this._maxValue);
      }
    }
  }
  else
  {
    //only min
    if(this._minValue)
    {
      try
      {
        minDate = (this._minISODate == null) ? 
                    converter.getAsObject (this._minValue).getTime ():
                    isoConverter.getAsObject (this._minISODate).getTime ();
      }
      catch (e)
      {
        // Make the validator lenient: let the server convert/validate if 
        // client conversion fails
        return value;
      }

      if(dateTime >= minDate)
      {
        return value;
      }
      else
      {
        var key = "org.apache.myfaces.trinidad.validator.DateTimeRangeValidator.MINIMUM";
      if(this._messages && this._messages["min"])
        {
          facesMessage = _createCustomFacesMessage(TrMessageFactory.getSummaryString(key),
                                        this._messages["min"],
                                        label,
                                        ""+converter.getAsString(value),
                                        ""+this._minValue);
        }
      else
      {
          facesMessage = _createFacesMessage(key,
                                        label,
                                        ""+converter.getAsString(value),
                                        ""+this._minValue);
      }
      }
    }
    //max only
    else if(this._maxValue)
    {
      try
      {
        maxDate = (this._maxISODate == null) ? 
                    converter.getAsObject (this._maxValue).getTime ():
                    isoConverter.getAsObject (this._maxISODate).getTime ();
      }
      catch (e)
      {
        // Make the validator lenient: let the server convert/validate if 
        // client conversion fails
        return value;
      }
      if(dateTime <= maxDate)
      {
        return value;
      }
      else
      {
        var key = "org.apache.myfaces.trinidad.validator.DateTimeRangeValidator.MAXIMUM";
        if(this._messages && this._messages["max"])
        {
          facesMessage = _createCustomFacesMessage(TrMessageFactory.getSummaryString(key),
                                        this._messages["max"],
                                        label,
                                        ""+converter.getAsString(value),
                                        ""+this._maxValue);
        }
        else
        {
          facesMessage = _createFacesMessage(key,
                                        label,
                                        ""+converter.getAsString(value),
                                        ""+this._maxValue);
        }
      }
    }
    else
    {
      //no min/max specified
      return value;
    }
  }
  throw new TrConverterException(facesMessage);
}