Exemple #1
0
 public function isValid($value)
 {
     // this line populates the "%value%" variables in the error messages
     $this->_setValue($value);
     if (($timestamp = strtotime($value)) === false) {
         $this->_error(self::NOT_DATE);
         return false;
     }
     // check format - convert into ISO-8601 format
     if (!Inspekt::isDate(date('o-m-N', $timestamp))) {
         // this line will insert the error message in the list of errors to
         // be returned to the caller
         $this->_error(self::NOT_DATE);
         return false;
     }
     return true;
 }
Exemple #2
0
 /**
  * Returns $value if it is a valid date, FALSE otherwise. The
  * date is required to be in ISO 8601 format.
  *
  * @param mixed $key
  * @return mixed
  *
  * @tag validator
  */
 function testDate($key)
 {
     if (!$this->keyExists($key)) {
         return false;
     }
     if (Inspekt::isDate($this->_getValue($key))) {
         return $this->_getValue($key);
     }
     return FALSE;
 }
 /**
  * Generated from @assert ('2-6-30') === TRUE.
  */
 public function testIsDate4()
 {
     $this->assertSame(TRUE, Inspekt::isDate('2-6-30'));
 }
/**
 * cpgValidateDate()
 *
 * Returns $date if $date contains a valid date string representation (yyyy-mm-dd). Returns an empty string if not.
 *
 * @param mixed $date
 * @return $return
**/
function cpgValidateDate($date)
{
    if (Inspekt::isDate($date)) {
        return $date;
    } else {
        return '';
    }
}
Exemple #5
0
 /**
  * Returns $value if it is a valid date, FALSE otherwise. The
  * date is required to be in ISO 8601 format.
  *
  * @param mixed $key
  * @return mixed
  * @throws Exception
  * @tag validator
  */
 public function testDate($key)
 {
     $value = $this->getValueOrNull($key);
     if (!is_null($value) && Inspekt::isDate($value)) {
         return $value;
     }
     return false;
 }