/** * Validates a week value. * * @param string $value The value to validate. * * @return bool|string Returns boolean TRUE upon successfull validation, and an error message string upon failure. */ public function validate(&$value) { $return = parent::validate($value); if ($return !== true) { return $return; } if (isset($value) && strlen(trim($value)) > 0) { $msglbl = get::array_def($this->attributes, 'msglbl', get::array_def($this->attributes, 'name', $this->getId())); $valid = is::dt_week($value); if ($valid === false) { return sprintf('"%s" does not have a valid month. Months must be in the format YYYY-mm.', $msglbl); } $mode = get::array_def($this->attributes, 'datemode', 'html'); $min = get::array_def($this->attributes, 'min', false); if (is_object($min) && $min instanceof cDateTime) { if ($valid->lessThan($min)) { switch ($mode) { case 'html': break; case 'us': $min = $min->format_us(); break; default: $min = $min->format($mode); break; } return sprintf('"%s" cannot be before "%s".', $msglbl, $min); } } $max = get::array_def($this->attributes, 'max', false); if (is_object($max) && $max instanceof cDateTime) { if ($max->lessThan($valid)) { switch ($mode) { case 'html': break; case 'us': $max = $max->format_us(); break; default: $max = $max->format($mode); break; } return sprintf('"%s" cannot be after "%s".', $msglbl, $max); } } $value = $valid; } return true; }