Reputation: 360
I have a datetimepicker with stepping has value 45.But when I increase the minutes ,the hour field increases with 1 hour.
$("#startDate").datetimepicker({ format:'YYYY/MM/DD HH:mm' , locale: g_state_language, useCurrent: false, stepping: 45, defaultDate: false, sideBySide:true });
12:00 to 12:45 is working, but 12:45 increase shows 01:45 instead of 01:30
Upvotes: 3
Views: 1785
Reputation: 3300
datetimepicker
's stepping
works with rounding step. So to work around your issue, I've added one new options like forceMinuteStep
into plugin.
Check below sample how I use stepping
and forceMinuteStep
both together to achieve step irrespective of rounding value.
// Below changes I made in datetimepicker library.
setValue = function (targetMoment) {
...
...
// Only round if forceMinuteStep is not true otherwise use incremental value directly.
if (options.stepping !== 1 && !options.forceMinuteStep) {
var roundedMins = Math.round(targetMoment.minutes() / options.stepping) * options.stepping;
targetMoment.minutes((roundedMins) % 60).seconds(0);
targetMoment.minutes((Math.round(targetMoment.minutes() / options.stepping) * options.stepping) % 60).seconds(0);
}
...
}
How I initiated plugin with forceMinuteStep:true
.
$('#datetimepicker1').datetimepicker({
defaultDate: moment('03/25/2018 08:45'),
stepping: 45,
forceMinuteStep: true
});
Upvotes: 1