public function validateDate($value, $options = [], array $context = [])
{
if (!$value) {
if (!empty($options['allowEmpty'])) {
return true;
}
return false;
}
$format = !empty($options['format']) ? $options['format'] : 'ymd';
if (!is_object($value)) {
$value = new Time($value);
}
$date = $value->format(FORMAT_DB_DATE);
if (!empty($options['allowEmpty']) && (empty($date) || $date == DEFAULT_DATE)) {
return true;
}
if (Validation::date($date, $format)) {
// after/before?
$days = !empty($options['min']) ? $options['min'] : 0;
if (!empty($options['after']) && isset($context['data'][$options['after']])) {
$compare = $value->subDays($days);
/* @var \Cake\I18n\Time $after */
$after = $context['data'][$options['after']];
if ($after->gt($compare)) {
return false;
}
}
if (!empty($options['before']) && isset($context['data'][$options['before']])) {
$compare = $value->addDays($days);
/* @var \Cake\I18n\Time $before */
$before = $context['data'][$options['before']];
if ($before->lt($compare)) {
return false;
}
}
return true;
}
return false;
}