jquery-timepicker
jquery-timepicker copied to clipboard
Won't work without hours (e.g. mins:secs only)
I have a case where I'm using timepicker for a duration picker, in seconds up to 15 mins;
<input type="text" data-time-format="i:s" data-none-option="true" data-step="0.0167" data-min-time="00:00:00" data-max-time="00:15:00" />
Luckily, step still works when not an integer. This gives me a picker with "00:00" to "14:59".
Unfortunately typing into the input field (which I need) always gets parsed as hours:mins:secs, and so typing "10:23" for example, gets changed to "23:00".
The _time2int function is using a hard-coded regex, ignoring the options format.
// try to parse time input
var pattern = new RegExp('^'+ampmRegex+'([0-9]?[0-9])\\W?([0-5][0-9])?\\W?([0-5][0-9])?'+ampmRegex+'$');
It would be better if it first tried to use the provided format, e.g. my "i:s", as it would then correctly parse the right value. It can fall back to this generic if necessary.
Agreed! What's needed is a function to convert the format string into a regex.