/** * Determine if the date is within the specified range. * Uses pradoParseDate and strtotime to get the date from string. * @param string date as string to validate * @return boolean true if within range. */ protected function isValidDate($value) { $minValue = $this->getMinValue(); $maxValue = $this->getMaxValue(); $valid = true; $dateFormat = $this->getDateFormat(); if (strlen($dateFormat)) { $value = pradoParseDate($value, $dateFormat); if (strlen($minValue)) { $valid = $valid && $value >= pradoParseDate($minValue, $dateFormat); } if (strlen($maxValue)) { $valid = $valid && $value <= pradoParseDate($maxValue, $dateFormat); } return $valid; } else { $value = strtotime($value); if (strlen($minValue)) { $valid = $valid && $value >= strtotime($minValue); } if (strlen($maxValue)) { $valid = $valid && $value <= strtotime($maxValue); } return $valid; } }
/** * Parse the pair of values into the appropriate value type. * @param string value one * @param string second value * @return array appropriate type of the value pair, array($value1, $value2); */ protected function getComparisonValues($value1, $value2) { switch ($this->getValueType()) { case 'Integer': return array(intval($value1), intval($value2)); case 'Float': case 'Double': return array(floatval($value1), floatval($value2)); case 'Currency': if (preg_match('/[-+]?([0-9]*\\.)?[0-9]+([eE][-+]?[0-9]+)?/', $value1, $matches)) { $value1 = floatval($matches[0]); } else { $value1 = 0; } if (preg_match('/[-+]?([0-9]*\\.)?[0-9]+([eE][-+]?[0-9]+)?/', $value2, $matches)) { $value2 = floatval($matches[0]); } else { $value2 = 0; } return array($value1, $value2); case 'Date': $dateFormat = $this->getDateFormat(); if (strlen($dateFormat)) { return array(pradoParseDate($value1, $dateFormat), pradoParseDate($value2, $dateFormat)); } else { return array(strtotime($value1), strtotime($value2)); } } return array($value1, $value2); }