From 533112e2f552752114df435b7862334f76270ab9 Mon Sep 17 00:00:00 2001 From: Dayle Rees Date: Wed, 21 Mar 2012 21:07:10 +0000 Subject: [PATCH] added before and after date filters Signed-off-by: Dayle Rees --- application/language/en/validation.php | 2 + laravel/validator.php | 54 ++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/application/language/en/validation.php b/application/language/en/validation.php index 8285f1e9..0a3c85d6 100644 --- a/application/language/en/validation.php +++ b/application/language/en/validation.php @@ -59,6 +59,8 @@ ), "unique" => "The :attribute has already been taken.", "url" => "The :attribute format is invalid.", + "before" => "The :attribute field must contain a date before :date.", + "after" => "The :attribute field must contain a date after :date.", /* |-------------------------------------------------------------------------- diff --git a/laravel/validator.php b/laravel/validator.php index 77ac724a..b238ce13 100644 --- a/laravel/validator.php +++ b/laravel/validator.php @@ -646,6 +646,32 @@ protected function validate_mimes($attribute, $value, $parameters) return false; } + /** + * Validate the date is before a given date. + * + * @param string $attribute + * @param mixed $value + * @param array $parameters + * @return bool + */ + protected function validate_before($attribute, $value, $parameters) + { + return (strtotime($value) < strtotime($parameters[0])); + } + + /** + * Validate the date is after a given date. + * + * @param string $attribute + * @param mixed $value + * @param array $parameters + * @return bool + */ + protected function validate_after($attribute, $value, $parameters) + { + return (strtotime($value) > strtotime($parameters[0])); + } + /** * Get the proper error message for an attribute and rule. * @@ -877,6 +903,34 @@ protected function replace_different($message, $attribute, $rule, $parameters) return str_replace(':other', $parameters[0], $message); } + /** + * Replace all place-holders for the before rule. + * + * @param string $message + * @param string $attribute + * @param string $rule + * @param array $parameters + * @return string + */ + protected function replace_before($message, $attribute, $rule, $parameters) + { + return str_replace(':date', $parameters[0], $message); + } + + /** + * Replace all place-holders for the after rule. + * + * @param string $message + * @param string $attribute + * @param string $rule + * @param array $parameters + * @return string + */ + protected function replace_after($message, $attribute, $rule, $parameters) + { + return str_replace(':date', $parameters[0], $message); + } + /** * Get the displayable name for a given attribute. *