Download the PHP package aegisora/date-format-rule without Composer
On this page you can find all versions of the php package aegisora/date-format-rule. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aegisora/date-format-rule
More information about aegisora/date-format-rule
Files in aegisora/date-format-rule
Package date-format-rule
Short Description Date Format Rule provides a simple, rule-based date/time format validation implementation for the Aegisora ecosystem
License MIT
Homepage https://github.com/Aegisora/date-format-rule
Informations about the package date-format-rule
Aegisora Date Format Rule
Date Format Rule provides a simple, rule-based date/time format validation implementation for the Aegisora ecosystem.
It is built on top of aegisora/rule-contract and follows its strict validation architecture, ensuring consistent and predictable behavior across applications.
This rule is useful for validating user input, form fields, birth dates, appointment times, API request parameters, imported data, and any other string that must conform to a specific date/time format.
๐ Table of Contents
- Features
- Installation
- Core Concept
- Basic Usage
- Valid vs Invalid
- Validation Result
- Time Zones
- Guardian Usage
- Real-World Examples
- Constructor & API
- Architecture
- License
- Contributing
- Support
โจ Features
- ๐น Lightweight and dependency-free except
aegisora/rule-contract - ๐น Validates a string against any PHP date/time format (
Y-m-d,d/m/Y H:i,H:i:s, ...) - ๐น Supports the full PHP format syntax, including escaped literals (
\T) - ๐น Exhaustive check โ rejects overflow dates (
2026-02-31), out-of-range values, and non-canonical input the parser silently tolerates - ๐น Optional time zone support
- ๐น Rejects non-string input as an invalid context
- ๐น Fully compatible with Aegisora validation pipeline
- ๐น Strict
ContextโResultvalidation flow - ๐น No raw booleans โ only structured results
- ๐น Safe execution via base
Ruleabstraction - ๐น Ready to use out of the box
๐ฆ Installation
๐ Core Concept
This package implements a single validation rule:
- accepts a string value via
Context - checks whether the string is a valid date/time that strictly matches the configured format
- returns a standardized
Result
Under the hood it wraps the common โ and easy to get wrong โ boilerplate:
into a reusable rule that reports its outcome through a Result object instead of a raw boolean.
๐๏ธ Basic Usage
โ Valid vs Invalid
The rule passes when the string is a real date/time that renders back exactly as the input under the configured format, and fails otherwise.
Dates
Strict formatting
Times and combined formats
๐งช Validation Result
If the string is a valid date/time matching the format, the rule returns a valid result.
$result->isValid(); // true
If the string does not match the format, the rule returns an invalid result.
If the context value is not a string, the rule throws:
Aegisora\RuleContract\Exceptions\InvalidRuleContextException
If the configured format is an empty string, the rule throws:
Aegisora\RuleContract\Exceptions\InvalidRuleContextException
๐ Time Zones
An optional DateTimeZone can be passed as the second argument. It is used while parsing the value, which matters for formats that carry time information.
If the format itself carries a time zone (e, T, P, O), that value takes precedence and the argument is ignored.
๐ Guardian Usage
This rule can be used together with aegisora/guardian to build fluent validation pipelines.
If the value does not match the format, Guardian throws the provided domain exception.
๐งญ Real-World Examples
Date Format Rule is useful for enforcing date/time constraints before values are persisted or processed.
Examples
๐งฉ Constructor & API
new DateFormatRule($format);
- creates a rule that passes when the value is a valid date/time strictly matching the PHP
$format
new DateFormatRule($format, $timeZone);
- additionally applies the given
DateTimeZonewhile parsing the value
(new DateFormatRule($format))->validate($context);
$contextโContextwrapping the string value to validate
๐๏ธ Architecture
This package relies on aegisora/rule-contract.
Flow:
validate()is calledContextis passed in- The configured format is checked; an empty format raises
InvalidRuleContextException - The string value is extracted from context (non-strings raise
InvalidRuleContextException) - The value is parsed with
DateTimeImmutable::createFromFormat(), checked againstgetLastErrors()for overflow/out-of-range warnings, and round-tripped back through the format to reject non-canonical input Resultis returned โ valid on a strict match, invalid with thedate_format_rulecode otherwise
All logic is safely handled by Rule contract.
โ๏ธ License
This package is open-source and licensed under the MIT License. See the LICENSE for details.
๐ฑ Contributing
Contributions are welcome and greatly appreciated! See the CONTRIBUTING for details.
๐ Support
If you find this project useful, please consider giving it a star on GitHub!
It helps the project grow and motivates further development.