Skip to content

Commit

Permalink
Fix time validation for array data.
Browse files Browse the repository at this point in the history
Add an array to string cast for time data.

Refs #5611
  • Loading branch information
markstory committed Jan 29, 2015
1 parent 052e2e5 commit d889e90
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Validation/Validation.php
Expand Up @@ -400,6 +400,9 @@ public static function time($check)
if ($check instanceof \DateTime) {
return true;
}
if (is_array($check)) {
$check = static::_getDateString($check);
}
return static::_check($check, '%^((0?[1-9]|1[012])(:[0-5]\d){0,2} ?([AP]M|[ap]m))$|^([01]\d|2[0-3])(:[0-5]\d){0,2}$%');
}

Expand Down
25 changes: 25 additions & 0 deletions tests/TestCase/Validation/ValidationTest.php
Expand Up @@ -1558,6 +1558,31 @@ public function testTime()
$this->assertFalse(Validation::time('9:00'));
}

/**
* test time validation when passing an array
*
* @return void
*/
public function testTimeArray()
{
$date = ['hour' => 13, 'minute' => 14, 'second' => 15];
$this->assertTrue(Validation::time($date));

$date = [
'hour' => 1, 'minute' => 14, 'second' => 15,
'meridian' => 'am'
];
$this->assertTrue(Validation::time($date));

$date = [
'hour' => 'farts', 'minute' => 'farts'
];
$this->assertFalse(Validation::time($date));

$date = [];
$this->assertFalse(Validation::time($date));
}

/**
* testBoolean method
*
Expand Down

0 comments on commit d889e90

Please sign in to comment.