PHPackages                             oh/date-extra-validator-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. oh/date-extra-validator-bundle

ActiveSymfony-bundle[Validation &amp; Sanitization](/categories/validation)

oh/date-extra-validator-bundle
==============================

Symfony2 Date Validator for Minimum and Maximum Constraints

4198.9k↓52.4%2PHP

Since Aug 29Pushed 12y ago2 watchersCompare

[ Source](https://github.com/ollieLtd/OhDateExtraValidatorBundle)[ Packagist](https://packagist.org/packages/oh/date-extra-validator-bundle)[ RSS](/packages/oh-date-extra-validator-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

OhDateExtraValidatorBundle
==========================

[](#ohdateextravalidatorbundle)

A minimum and maximum date validator for Symfony2

Installation
------------

[](#installation)

Install this bundle as usual by adding to composer.json:

```
"oh/date-extra-validator-bundle": "dev-master"

```

Register the bundle in `app/AppKernel.php`:

```
// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Oh\DateExtraValidatorBundle\OhDateExtraValidatorBundle(),
    );
}

```

Usage
-----

[](#usage)

### Add the constraints to your model

[](#add-the-constraints-to-your-model)

```
...
use Oh\DateExtraValidatorBundle\Validator\Constraints as OhAssert;

/**
 * @ORM\Entity()
 */
class Event
{
    /**
     * @ORM\Column(type="datetime")
     *
     * @OhAssert\DateExtra(min="-1 year", max="+1 year", intlTimeFormat=\IntlDateFormatter::NONE)
     */
    protected $start_time;
}

```

Or in your yml (WARNING! untested - I use annotations)

```
Acme\DemoBundle\Entity\AcmeEntity:
    properties:
        start_time:
            - Oh\DateExtraValidatorBundle\Validator\Constraints\DateExtra: {min="-1 year", max="+1 year", intlTimeFormat=\IntlDateFormatter::NONE}

```

Options
-------

[](#options)

### Messages

[](#messages)

When you validate your model through a form you should see the error messages as defined in Oh\\DateExtraValidatorBundle\\Validator\\Constraints\\DateExtra.

```
public $minMessage = 'You cannot choose a date before {{ min }}.';
public $maxMessage = 'You cannot choose a date after {{ max }}.';
public $invalidMessage = 'The date is invalid';
...

```

Each message can use `{{ min }}`, `{{ max }}` and `{{ value }}` so you can for example put:

```
/**
 * @OhAssert\DateExtra(minMessage="The date you supplied, {{ value }}, should be between {{ min }} and {{ max }}", min="-1 year", max="+1 year")
 */

```

The format of the date in the error messages can be a normal date string or an [IntlDateFormatter](http://uk.php.net/manual/en/class.intldateformatter.php) date.

```
/**
 * @OhAssert\DateExtra(format="Y-m-d",min="-1 year", max="+1 year")
 * or
 * @OhAssert\DateExtra(intlDateFormat=\IntlDateFormatter::LONG, intlTimeFormat=\IntlDateFormatter::LONG, min="-1 year", max="+1 year")
 */

```

For the UK timezone Europe/London the 2 examples above would output "You cannot choose a date before 2011-09-04." and "You cannot choose a date before September 4, 2011 8:10:34 PM GMT+01:00."

You can also set the timezone manually by specifying it in the constructor (eg `timezone="Europe/London"`)

### Valid values

[](#valid-values)

The class can handle most date formats; `\DateTime`, `array('year'=>2012,'month'=>9,'day'=>4)`, unix timestamp (eg `1346789811`), string (eg 2012-09-04) or an object that returns one of these values in \_\_toString()

Tests
-----

[](#tests)

[![Build Status](https://camo.githubusercontent.com/dbf0840da9d5ff7e409246ae1d7365bdbd8d32079c82090286dd1e2c64545c05/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6f6c6c69654c74642f4f6844617465457874726156616c696461746f7242756e646c652e706e67)](http://travis-ci.org/ollieLtd/OhDateExtraValidatorBundle)

Credits
-------

[](#credits)

- Ollie Harridge [ollietb](https://github.com/ollietb) as main author.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c292a6c56c272b9c31da4a195de55521accd66989e84cd7e0767423a6743a275?d=identicon)[ollietb](/maintainers/ollietb)

---

Top Contributors

[![ollietb](https://avatars.githubusercontent.com/u/342090?v=4)](https://github.com/ollietb "ollietb (16 commits)")[![bonswouar](https://avatars.githubusercontent.com/u/615053?v=4)](https://github.com/bonswouar "bonswouar (1 commits)")

### Embed Badge

![Health badge](/badges/oh-date-extra-validator-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/oh-date-extra-validator-bundle/health.svg)](https://phpackages.com/packages/oh-date-extra-validator-bundle)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
