This repository was archived by the owner on Mar 13, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed
Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 3131
3232## Date Rules
3333
34+ - [ DateTime] ( 03-rules_date-time.md )
3435- [ Timezone] ( 03-rules_timezone.md )
3536
3637## Choice Rules
Original file line number Diff line number Diff line change 1+ # DateTime
2+
3+ Validates that a given value is a valid datetime in a specific format.
4+
5+ ``` php
6+ DateTime(
7+ string $format = 'Y-m-d H:i:s',
8+ ?string $message = null
9+ );
10+ ```
11+
12+ ## Basic Usage
13+
14+ ``` php
15+ // default "Y-m-d H:i:s"
16+ Validator::dateTime()->validate('2024-01-01 00:00:00'); // true
17+ Validator::dateTime()->validate('2024-01-01'); // false
18+
19+ // validate date
20+ Validator::dateTime(format: 'Y-m-d')->validate('2024-01-01'); // true
21+ Validator::dateTime(format: 'Y-m-d')->validate('2024-01-35'); // false
22+
23+ // validate time
24+ Validator::dateTime(format: 'H:i:s')->validate('21:00:00'); // true
25+ Validator::dateTime(format: 'H:i:s')->validate('35:00:00'); // false
26+ ```
27+
28+ > [ !NOTE]
29+ > An ` UnexpectedValueException ` will be thrown when the input value is not a ` string ` or an object implementing ` \Stringable ` .
30+
31+ ## Options
32+
33+ ### ` format `
34+
35+ type: ` string ` default: ` Y-m-d H:i:s `
36+
37+ Format of the datetime to be validated.
38+ Check all formatting options [ here] ( https://www.php.net/manual/en/datetimeimmutable.createfromformat.php ) .
39+
40+ ### ` message `
41+
42+ type: ` ?string ` default: ` The {{ name }} value is not a valid datetime. `
43+
44+ Message that will be shown when the input value is not a valid datetime.
45+
46+ The following parameters are available:
47+
48+ | Parameter | Description |
49+ | ----------------| ---------------------------|
50+ | ` {{ value }} ` | The current invalid value |
51+ | ` {{ name }} ` | Name of the invalid value |
52+ | ` {{ format }} ` | The datetime format |
53+
54+ ## Changelog
55+
56+ - ` 0.8.0 ` Created
You can’t perform that action at this time.
0 commit comments