If using a comparison validator for comparing time fields, it doesn't validate if either time has a single-digit minute value.
Though the minutes show as double-digits in the dropdown, when it gets to the code:
elseif ($components[$entry[$count]['key']]['type'] === 'time') {
$time = $value['hour'] . ':' . $value['minute'];
$value['minute'] is a single-digit number. This makes the call to strtotime() fail to convert it to a timestamp every time for such values.
This can be fixed by padding the single-digit minute values to two digits with a zero.
$time = $value['hour'] . ':' . str_pad($value['minute'], 2, '0', STR_PAD_LEFT);
Comments
Comment #2
solideogloria commentedComment #3
liam morlandComment #5
liam morlandThanks!
Comment #7
liam morlandLooking at this again, I can't reproduce the problem. Both lines below output
1564146060, so leading zeros do nothing. I'm inclined to revert the commit unless someone can find a case in which it is needed.Comment #8
solideogloria commentedThe error only happens if
'ampm'is set.See in an online interpreter.
If you use the "fixed" code, it will output the time, otherwise not. Setting
'ampm'to NULL will make it work for both.Comment #9
solideogloria commentedComment #10
liam morlandThanks. For the record, this returns FALSE:
strtotime('9:1 AM')