Skip to content

Commit c1c631b

Browse files
Mark Salmonjasonmccreary
authored andcommitted
Add date rule for datetime datatypes
1 parent ef839de commit c1c631b

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Translators/Rules.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public static function fromColumn(Column $column)
5656
$rules = array_merge($rules, ['in:' . implode(',', $column->attributes())]);
5757
}
5858

59+
if (in_array($column->dataType(), ['date', 'datetime', 'datetimetz'])) {
60+
$rules = array_merge($rules, ['date']);
61+
}
62+
5963
if ($column->attributes()) {
6064
if (in_array($column->dataType(), ['string', 'char'])) {
6165
$rules = array_merge($rules, ['max:' . implode($column->attributes())]);

tests/Feature/Translators/RulesTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,17 @@ public function forColumn_returns_in_rule_for_enums_and_sets()
112112
$this->assertContains('in:2,4,6', Rules::fromColumn($column));
113113
}
114114

115+
/**
116+
* @test
117+
* @dataProvider dateDataTypesProvider
118+
*/
119+
public function forColumn_returns_date_rule_for_date_types($data_type)
120+
{
121+
$column = new Column('test', $data_type);
122+
123+
$this->assertContains('date', Rules::fromColumn($column));
124+
}
125+
115126
public function stringDataTypesProvider()
116127
{
117128
return [
@@ -145,4 +156,13 @@ public function numericDataTypesProvider()
145156
['unsignedTinyInteger'],
146157
];
147158
}
159+
160+
public function dateDataTypesProvider()
161+
{
162+
return [
163+
['date'],
164+
['datetime'],
165+
['datetimetz'],
166+
];
167+
}
148168
}

0 commit comments

Comments
 (0)