2017 © Pedro Peláez
 

library constraints-date

DateTime Constraints Library. Use this to add constraints to a validator and verify DateTime objects pass those constraints.

image

zogot/constraints-date

DateTime Constraints Library. Use this to add constraints to a validator and verify DateTime objects pass those constraints.

  • Friday, July 7, 2017
  • by zogot
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,748 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 33 % Grown

The README.md

DateTime Constraints

Travis, (*1)

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)

Install

Via Composer, (*3)

$ composer require zogot/constraints-date

Usage

<?php
require 'vendor/autoload.php';

use Zogo\DateConstraints\Constraints\Day\DayConstraintInterface;
use Zogo\DateConstraints\Constraints\Day\SpecificDayConstraint;
use Zogo\DateConstraints\Constraints\Month\MonthConstraintInterface;
use Zogo\DateConstraints\Constraints\Month\SpecificMonthConstraint;
use Zogo\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

Tests

We have a full PHPUnit test suite. To run the tests, run the following command from the project folder., (*5)

$ composer test

Contributors

Contributions are welcome and will be fully credited., (*6)

License

The MIT License (MIT). Please see License File for more information., (*7)

The Versions

07/07 2017

dev-master

9999999-dev

DateTime Constraints Library. Use this to add constraints to a validator and verify DateTime objects pass those constraints.

  Sources   Download

MIT

The Development Requires

by Leon Rowland

07/07 2017

1.2.0

1.2.0.0

DateTime Constraints Library. Use this to add constraints to a validator and verify DateTime objects pass those constraints.

  Sources   Download

MIT

The Development Requires

by Leon Rowland

06/07 2017

1.1.0

1.1.0.0

DateTime Constraints Library. Use this to add constraints to a validator and verify DateTime objects pass those constraints.

  Sources   Download

MIT

The Development Requires

by Leon Rowland

06/07 2017

1.0.2

1.0.2.0

DateTime Constraints Library. Use this to add constraints to a validator and verify DateTime objects pass those constraints.

  Sources   Download

MIT

The Development Requires

by Leon Rowland

06/07 2017

1.0.1

1.0.1.0

DateTime Constraints Library. Use this to add constraints to a validator and verify DateTime objects pass those constraints.

  Sources   Download

MIT

The Development Requires

by Leon Rowland

06/07 2017

1.0.0

1.0.0.0

DateTime Constraints Library. Use this to add constraints to a validator and verify DateTime objects pass those constraints.

  Sources   Download

MIT

The Development Requires

by Leon Rowland