dev-master
9999999-devDateTime Constraints Library. Use this to add constraints to a validator and verify DateTime objects pass those constraints.
MIT
The Development Requires
by Leon Rowland
DateTime Constraints Library. Use this to add constraints to a validator and verify DateTime objects pass those constraints.
DateTime Constraints Library. Use this to add constraints to a validator and verify DateTime objects pass those constraints. Useful for Event or Calendar libraries., (*2)
Via Composer, (*3)
$ composer require clearvox/constraints-date
<?php require 'vendor/autoload.php'; use Clearvox\DateConstraints\Constraints\Day\DayConstraintInterface; use Clearvox\DateConstraints\Constraints\Day\SpecificDayConstraint; use Clearvox\DateConstraints\Constraints\Month\MonthConstraintInterface; use Clearvox\DateConstraints\Constraints\Month\SpecificMonthConstraint; use Clearvox\DateConstraints\Validators\AndValidator; // Build a validator instance $validator = new AndValidator(); // Add constraints to that validator $validator ->addConstraint(new SpecificDayConstraint(DayConstraintInterface::TUESDAY)) ->addConstraint(new SpecificMonthConstraint(MonthConstraintInterface::FEBRUARY)) // Attempt a datetime $validator->validFor(new DateTime('Tuesday, 16 Feb 2016 13:00:00 GMT')) // true $validator->validFor(new DateTime('Monday, 15 Feb 2016 13:00:00 GMT')) // false
Another example with a range of time, useful for workday validation, (*4)
<?php // Build the validator instance $validator = new AndValidator(); // Add Constraints to that validator $validator ->addConstraint(new BetweenTimeConstraint(new DateTime('09:00:00'), new DateTime('17:00:00')) // Attempt a datetime $validator->validFor(new DateTime('Tuesday, 16 Feb 2016 13:00:00 GMT')) // true $validator->validFor(new DateTime('Tuesday, 16 Feb 2016 18:00:00 GMT')) // false
We have a full PHPUnit test suite. To run the tests, run the following command from the project folder., (*5)
$ composer test
Contributions are welcome and will be fully credited., (*6)
The MIT License (MIT). Please see License File for more information., (*7)
DateTime Constraints Library. Use this to add constraints to a validator and verify DateTime objects pass those constraints.
MIT