-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Fixed time constraint (support formats H, H:i and H:i:s) #9163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
271fbfd
483fcf0
212d81f
1b73286
a3fde0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,22 +47,20 @@ public function validate($value, Constraint $constraint) | |
/** | ||
* Returns the regex pattern for validating | ||
* | ||
* @param $withMinutes | ||
* @param $withSeconds | ||
* @param Boolean $withMinutes | ||
* @param Boolean $withSeconds | ||
* @return string | ||
*/ | ||
protected function getPattern($withMinutes, $withSeconds) | ||
{ | ||
// pattern for hours | ||
$pattern = "(0[0-9]|1[0-9]|2[0-3])"; | ||
|
||
if ($withMinutes) | ||
{ | ||
if ($withMinutes) { | ||
// pattern for minutes | ||
$pattern .= "(:([0-5][0-9]))"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need the question mark here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup, mistype. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moreover, looking at how the regex is captured, I Think every capturing group should be not capturing... |
||
|
||
if ($withSeconds) | ||
{ | ||
if ($withSeconds) { | ||
// because the pattern for seconds is the same as that for minutes, we repeat it twice | ||
$pattern .= "{2}"; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
([01][0-9]|2[0-3])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm... single digit hour value like 5:00 is not valid? We could add an option "allow_single_digit"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(?:[01]?\d|2[0-3])