I am using jQuery bootstrap ClockPicker and need to get only times that their minutes are divisible by 5. For example if user selects 13:08, the ClockPicker should select 13:05.
I didn't found a way to do this with the API. So I wrote one using afterDone
callback.
I parse the input's value and make the change to get the new minutes value.
var clockpicker = $('.clockpicker').clockpicker({
afterDone: function() {
clockpicker.val(round());
}
}).find('input');
function round() {
var time = clockpicker.val(),
arr = time.split(':'),
hour = arr[0],
min = arr[1],
newMin = (Math.floor(parseInt(min) / 5)) * 5;
return hour + ':' + (newMin > 9 ? '' : '0') + newMin;
}
http://jsbin.com/lopufu/edit?html,js