承接 clearvox/constraints-date 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

clearvox/constraints-date

Composer 安装命令:

composer require clearvox/constraints-date

包简介

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

README 文档

README

Travis

DateTime Constraints Library. Use this to add constraints to a validator and verify DateTime objects pass those constraints. Useful for Event or Calendar libraries.

Install

Via Composer

$ composer require clearvox/constraints-date

Usage

<?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

<?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.

$ composer test

Contributors

Contributions are welcome and will be fully credited.

License

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

统计信息

  • 总下载量: 12.27k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 6
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-16