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.
If you don't mind make changes into Clockpicker (i had to do it for IE), adds an unofficial option like "roundmodfive" in bootstrap-clockpicker.js:
1. change this
// Hours and minutes are selected
ClockPicker.prototype.done = function() {
raiseCallback(this.options.beforeDone);
this.hide();
var last = this.input.prop('value'),
value = leadingZero(this.hours) + ':' + leadingZero(this.minutes);
if (this.options.twelvehour) {
value = value + this.amOrPm;
}
...
2. By this
// Hours and minutes are selected
ClockPicker.prototype.done = function() {
raiseCallback(this.options.beforeDone);
this.hide();
var last = this.input.prop('value');
//Unofficial option added
/*
Just an explain:
I like rounding. Thus, for example 43min => 45 and 42min => 40.
The minutes are base 60, so you have to make modulus 60.
*/
if (this.options.roundmodfive) {
this.minutes = (Math.round(parseInt(this.minutes) / 5)) * 5 % 60;
}
var value = leadingZero(this.hours) + ':' + leadingZero(this.minutes);
if (this.options.twelvehour) {
value = value + this.amOrPm;
}
...