respect-validation/docs/rules/DateTimeDiff.md
Henrique Moody 061a3c9c09
Rename method "validate()" to "isValid()"
The method has been renamed some time ago, but I haven't updated the
documentation to cause less confusion. Now that I want to start updating
the documentation, I switched the default branch on GitHub to the latest
stable version, so I assume there will be less confusion in the
documentation, and I can start updating the docs for the next version.
2024-12-02 22:11:57 +01:00

1.4 KiB

DateTimeDiff

  • DateTimeDiff(string $type, Validatable $rule)
  • DateTimeDiff(string $type, Validatable $rule, string $format)

Validates the difference of date/time against a specific rule.

The $format argument should follow PHP's date() function. When the $format is not given, this rule accepts Supported Date and Time Formats by PHP (see strtotime()).

v::dateTimeDiff('years', v::equals(7))->isValid('7 years ago'); // true
v::dateTimeDiff('years', v::equals(7))->isValid('7 years ago + 1 minute'); // false

v::dateTimeDiff('years', v::greaterThan(18), 'd/m/Y')->isValid('09/12/1990'); // true
v::dateTimeDiff('years', v::greaterThan(18), 'd/m/Y')->isValid('09/12/2023'); // false

v::dateTimeDiff('months', v::between(1, 18))->isValid('5 months ago'); // true

The supported types are:

  • years
  • months
  • days
  • hours
  • minutes
  • seconds
  • microseconds

Categorization

  • Date and Time

Changelog

Version Description
3.0.0 Created from Age, MinAge, and MaxAge

See also: