1. Go to this page and download the library: Download aegisora/date-format-rule library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
aegisora / date-format-rule example snippets
$date = DateTimeImmutable::createFromFormat('!' . $format, $value);
$errors = DateTimeImmutable::getLastErrors();
// $date !== false, no warnings/errors, and $date->format($format) === $value
use Aegisora\RuleContract\Models\Context;
use Aegisora\Rules\DateFormatRule;
$result = (new DateFormatRule('Y-m-d'))->validate(Context::create('2026-08-31'));
if ($result->isValid()) {
// value is a valid date in the given format
} else {
// value does not match the format
}
(new DateFormatRule('Y-m-d'))->validate(Context::create('2026-08-31')); // valid — a real calendar date
(new DateFormatRule('Y-m-d'))->validate(Context::create('2024-02-29')); // valid — 2024 is a leap year
(new DateFormatRule('Y-m-d'))->validate(Context::create('2026-02-31')); // invalid — February has no 31st
(new DateFormatRule('Y-m-d'))->validate(Context::create('2026-02-29')); // invalid — 2026 is not a leap year
(new DateFormatRule('Y-m-d'))->validate(Context::create('2026-13-01')); // invalid — month out of range
(new DateFormatRule('Y-m-d'))->validate(Context::create('2026-8-3')); // invalid — missing leading zeros
(new DateFormatRule('Y-m-d'))->validate(Context::create('2026/08/31')); // invalid — wrong separator
(new DateFormatRule('Y-m-d'))->validate(Context::create('2026-08-31 extra')); // invalid — trailing garbage
(new DateFormatRule('Y-n-j'))->validate(Context::create('2026-8-3')); // valid — the format allows no leading zeros
(new DateFormatRule('H:i'))->validate(Context::create('14:30')); // valid
(new DateFormatRule('H:i:s'))->validate(Context::create('24:00:00')); // invalid — hour out of range
(new DateFormatRule('d F Y'))->validate(Context::create('31 August 2026')); // valid — textual month
(new DateFormatRule('Y-m-d\TH:i:s'))->validate(Context::create('2026-08-31T10:20:30')); // valid — escaped literal T
use Aegisora\RuleContract\Models\Context;
use Aegisora\Rules\DateFormatRule;
use DateTimeZone;
$rule = new DateFormatRule('Y-m-d H:i:s', new DateTimeZone('Europe/Moscow'));
$rule->validate(Context::create('2026-08-31 12:00:00')); // valid
use Aegisora\Guardian\Guardian;
use Aegisora\Rules\DateFormatRule;
use App\Exceptions\InvalidBirthDateException;
$guardian = new Guardian();
$guardian
->that($birthDate)
->must(new DateFormatRule('Y-m-d'), new InvalidBirthDateException())
->validate();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.