|
| 1 | +# DateTimeDiff |
| 2 | + |
| 3 | +- `DateTimeDiff(string $type, Validatable $rule)` |
| 4 | +- `DateTimeDiff(string $type, Validatable $rule, string $format)` |
| 5 | + |
| 6 | +Validates the difference of date/time against a specific rule. |
| 7 | + |
| 8 | +The `$format` argument should follow PHP's [date()][] function. When the `$format` is not given, this rule accepts |
| 9 | +[Supported Date and Time Formats][] by PHP (see [strtotime()][]). |
| 10 | + |
| 11 | +```php |
| 12 | +v::dateTimeDiff('years', v::equals(7))->validate('7 years ago'); // true |
| 13 | +v::dateTimeDiff('years', v::equals(7))->validate('7 years ago + 1 minute'); // false |
| 14 | + |
| 15 | +v::dateTimeDiff('years', v::greaterThan(18), 'd/m/Y')->validate('09/12/1990'); // true |
| 16 | +v::dateTimeDiff('years', v::greaterThan(18), 'd/m/Y')->validate('09/12/2023'); // false |
| 17 | + |
| 18 | +v::dateTimeDiff('months', v::between(1, 18))->validate('5 months ago'); // true |
| 19 | +``` |
| 20 | + |
| 21 | +The supported types are: |
| 22 | + |
| 23 | +* `years` |
| 24 | +* `months` |
| 25 | +* `days` |
| 26 | +* `hours` |
| 27 | +* `minutes` |
| 28 | +* `seconds` |
| 29 | +* `microseconds` |
| 30 | + |
| 31 | +## Categorization |
| 32 | + |
| 33 | +- Date and Time |
| 34 | + |
| 35 | +## Changelog |
| 36 | + |
| 37 | +| Version | Description | |
| 38 | +| ------: |--------------------------------------------| |
| 39 | +| 3.0.0 | Created from `Age`, `MinAge`, and `MaxAge` | |
| 40 | + |
| 41 | +*** |
| 42 | +See also: |
| 43 | + |
| 44 | +- [Date](Date.md) |
| 45 | +- [DateTime](DateTime.md) |
| 46 | +- [Max](Max.md) |
| 47 | +- [Min](Min.md) |
| 48 | +- [Time](Time.md) |
| 49 | + |
| 50 | +[date()]: http://php.net/date |
| 51 | +[DateTimeInterface]: http://php.net/DateTimeInterface |
| 52 | +[strtotime()]: http://php.net/strtotime |
| 53 | +[Supported Date and Time Formats]: http://php.net/datetime.formats |
0 commit comments