PHPackages                             chrisharrison/date-validator - 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. chrisharrison/date-validator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

chrisharrison/date-validator
============================

Historical date validator.

0.0.0(6y ago)07UNLICENSEDPHPPHP ^7.2

Since Sep 6Pushed 6y ago1 watchersCompare

[ Source](https://github.com/chrisharrison/date-validator)[ Packagist](https://packagist.org/packages/chrisharrison/date-validator)[ RSS](/packages/chrisharrison-date-validator/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

date-validator
==============

[](#date-validator)

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

[](#installation)

I've added this to Packagist, so you can use:

```
composer require chrisharrison/date-validator

```

Alternatively, you can clone the repository and run:

```
composer install

```

Running tests
-------------

[](#running-tests)

Run tests with:

```
vendor/bin/phpunit

```

Usage
-----

[](#usage)

You can inject the date validator like this:

```
final class SomeOtherFunctionality
{
    private $dateValidator;

    public function __construct(DateValidator $dateValidator)
    {
        $this->dateValidator = $dateValidator;
    }

    public function doSomethingWithDate(string $date)
    {
        if ($this->dateValidator->validate()->isValid()) {
            return 'A valid historical date';
        }
    }
}

```

This package comes with a default implementation. The `DefaultDateValidator` requires a `Clock` in order for it to compare dates. A `DefaultDateValidator` should be initialised within an IoC container. It can be constructed like this:

```
$dateValidator = new DefaultDateValidator(new SystemClock);

```

The `validate()` method returns a `DateValidatorResponse` value object with the following methods:

- `isValid(): bool` Whether the date is a valid historical date or not.
- `getMessage(): DateValidatorResponseMessage` Returns an enum with the following options:
    - `INVALID_DATE` The input date is not a valid date (e.g. 32/13/1994)
    - `NOT_A_DATE_IN_THE_PAST` The input date is valid but it's not in the past (e.g. 01/01/3033)
    - `INVALID_FORMAT` The input is not a date at all (e.g. 'jibberish')
    - If the date is valid then the message is a null version of `DateValidatorResponseMessage`

This package also [provides a singleton](src/Singleton) which can be used like this:

```
use ChrisHarrison\DateValidator\Singleton\DateValidator;

DateValidator::validateHistoricalDate('03/12/1999');

```

The singleton uses a DefaultDateValidator internally and `validateHistoricalDate()` works the same way as above.

My strategy
-----------

[](#my-strategy)

You can see the way that I approached this task my looking at my commit history.

Note on really historical dates
-------------------------------

[](#note-on-really-historical-dates)

The solution I've written handles dates back to the year 1 CE. It doesn't handle dates BCE. And bizarrely thinks that there is a year zero. If I was to devote more time to this - and there was a business case for it - I'd investigate that. \[OK I couldn't resist looking it up. It seems that PHP is using some implementation of ISO 8601 and not the Gregorian calendar\]

Note on PHP date formats
------------------------

[](#note-on-php-date-formats)

The stipulation that the input date format should be `DD/MM/YYYY` reminded me of an interesting quirk of certain PHP functions which I discussed in a [Stackoverflow answer](https://stackoverflow.com/questions/2444820/how-to-make-strtotime-parse-dates-in-australian-i-e-uk-format-dd-mm-yyyy/5619817#5619817) many years ago. Just a mildly interesting titbit 😄

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2442d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/296186?v=4)[Chris Harrison](/maintainers/chrisharrison)[@chrisharrison](https://github.com/chrisharrison)

---

Top Contributors

[![chrisharrison](https://avatars.githubusercontent.com/u/296186?v=4)](https://github.com/chrisharrison "chrisharrison (12 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/chrisharrison-date-validator/health.svg)

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

###  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)[nette/forms

📝 Nette Forms: generating, validating and processing secure forms in PHP. Handy API, fully customizable, server &amp; client side validation and mature design.

54013.2M450](/packages/nette-forms)[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)

PHPackages © 2026

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