Skip to content

Commit

Permalink
Accept , in datetime validation rules.
Browse files Browse the repository at this point in the history
The default en_US format outputs dates like 'd/m/y, H:i a' the comma
should be accepted by the default dmy validator.

Refs cakephp/app#291
  • Loading branch information
markstory committed Oct 16, 2015
1 parent 21607e0 commit 74cff9b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Validation/Validation.php
Expand Up @@ -447,7 +447,7 @@ public static function datetime($check, $dateFormat = 'ymd', $regex = null)
}
$parts = explode(' ', $check);
if (!empty($parts) && count($parts) > 1) {
$date = array_shift($parts);
$date = rtrim(array_shift($parts), ',');
$time = implode(' ', $parts);
$valid = static::date($date, $dateFormat, $regex) && static::time($time);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase/Validation/ValidationTest.php
Expand Up @@ -1576,6 +1576,8 @@ public function testDateTimeWithMeriadian()
$this->assertTrue(Validation::dateTime('12/04/2017 1:38 pm', ['dmy']));
$this->assertTrue(Validation::dateTime('12/04/2017 1:38pm', ['dmy']));
$this->assertTrue(Validation::dateTime('12/04/2017 1:38AM', ['dmy']));
$this->assertTrue(Validation::dateTime('12/04/2017, 1:38AM', ['dmy']));
$this->assertTrue(Validation::dateTime('28/10/2015, 3:21 PM', ['dmy']));
$this->assertFalse(Validation::dateTime('12/04/2017 58:38AM', ['dmy']));
}

Expand Down

0 comments on commit 74cff9b

Please sign in to comment.