Skip to content

Commit

Permalink
Merge pull request #15211 from tanden/fix/validation_time
Browse files Browse the repository at this point in the history
Back-porting from #14969 on CakePHP 4
  • Loading branch information
markstory committed Dec 10, 2020
2 parents c9c8499 + 3344557 commit 6ba9521
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Validation/Validation.php
Expand Up @@ -701,8 +701,7 @@ public static function iso8601($check)

/**
* Time validation, determines if the string passed is a valid time.
* Validates time as 24hr (HH:MM) or am/pm ([H]H:MM[a|p]m)
* Does not allow/validate seconds.
* Validates time as 24hr (HH:MM[:SS]) or am/pm ([H]H[:MM][:SS][a|p]m)
*
* @param string|\DateTimeInterface $check a valid time string/object
* @return bool Success
Expand All @@ -716,7 +715,7 @@ public static function time($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}$%');
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){1,2}$%');
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/TestCase/Validation/ValidationTest.php
Expand Up @@ -1646,6 +1646,12 @@ public function testTime()
$this->assertTrue(Validation::time('1:00pm'));
$this->assertFalse(Validation::time('13:00pm'));
$this->assertFalse(Validation::time('9:00'));
$this->assertFalse(Validation::time('00'));
$this->assertFalse(Validation::time('0'));
$this->assertFalse(Validation::time('09'));
$this->assertFalse(Validation::time('9'));
$this->assertFalse(Validation::time('10'));
$this->assertFalse(Validation::time('23'));
}

/**
Expand Down

0 comments on commit 6ba9521

Please sign in to comment.