2018-05-31 16:23:42 +02:00
|
|
|
# MaxAge
|
2018-01-29 14:23:30 +01:00
|
|
|
|
2018-05-31 16:23:42 +02:00
|
|
|
- `MaxAge(int $age)`
|
|
|
|
- `MaxAge(int $age, string $format)`
|
2018-01-29 14:23:30 +01:00
|
|
|
|
|
|
|
Validates a maximum age for a given date. The `$format` argument should be in
|
|
|
|
accordance to PHP's [date()][] function. When `$format` is not given this rule
|
|
|
|
accepts [Supported Date and Time Formats][] by PHP (see [strtotime()][]).
|
|
|
|
|
|
|
|
```php
|
2018-05-31 16:23:42 +02:00
|
|
|
v::maxAge(12)->validate('12 years ago'); // true
|
|
|
|
v::maxAge(12, 'Y-m-d')->validate('2013-07-31'); // true
|
2018-01-29 14:23:30 +01:00
|
|
|
|
2018-05-31 16:23:42 +02:00
|
|
|
v::maxAge(12)->validate('13 years ago'); // false
|
|
|
|
v::maxAge(18, 'Y-m-d')->validate('1988-09-09'); // false
|
2018-01-29 14:23:30 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
Using [Date](Date.md) before is a best-practice.
|
|
|
|
This rule does not accepts instances of [DateTimeInterface][].
|
|
|
|
|
2019-05-11 18:32:13 +02:00
|
|
|
## Categorization
|
|
|
|
|
|
|
|
- Date and Time
|
|
|
|
|
2018-01-29 14:23:30 +01:00
|
|
|
## Changelog
|
|
|
|
|
|
|
|
Version | Description
|
|
|
|
--------|-------------
|
|
|
|
2.0.0 | Created based on removed `Age` rule
|
|
|
|
|
|
|
|
***
|
|
|
|
See also:
|
|
|
|
|
|
|
|
- [Date](Date.md)
|
|
|
|
- [Max](Max.md)
|
|
|
|
- [Min](Min.md)
|
2018-05-31 16:23:42 +02:00
|
|
|
- [MinAge](MinAge.md)
|
2018-01-29 14:23:30 +01:00
|
|
|
|
|
|
|
[date()]: http://php.net/date
|
|
|
|
[DateTimeInterface]: http://php.net/DateTimeInterface
|
|
|
|
[strtotime()]: http://php.net/strtotime
|
|
|
|
[Supported Date and Time Formats]: http://php.net/datetime.formats
|