Reputation: 615
I'm pretty dumb in jQuery. I have an Ion Range Slider with the following settings:
$("#range_time").ionRangeSlider({
type: "double",
values: [
"08:00", "08:15", "08:30", "08:45",
"09:00", "09:15", "09:30", "09:45",
"10:00", "10:15", "10:30", "10:45",
"11:00", "11:15", "11:30", "11:45",
"12:00", "12:15", "12:30", "12:45",
"13:00", "13:15", "13:30", "13:45",
"14:00", "14:15", "14:30", "14:45",
"15:00", "15:15", "15:30", "15:45",
"16:00", "16:15", "16:30", "16:45",
"17:00", "17:15", "17:30", "17:45",
"18:00", "18:15", "18:30", "18:45",
"19:00"
],
from_min: 0,
to: 8,
drag_interval: true,
min_interval: 8,
});
How do I set from_min
to a nearest current time (if it's in range 8:00-17:00) instead from: 0
? Step is 15 minutes.
Upvotes: 0
Views: 1594
Reputation: 42044
After you have created the object or at creation time you can calculate the rigth value you are looking for:
var timeToRound = new Date();
var hh = timeToRound.getHours();
var mm = Math.round(timeToRound.getMinutes() / 15) * 15;
var froMin = 0;
if (hh >= 8 && hh < 19 || (hh == 19 && mm == 0)) {
froMin = (hh - 8) * 4 + (mm / 15);
}
var slider = $("#range_time").data("ionRangeSlider"); // changed the identifier to match the initial post example
slider.update({
from_min: froMin
});
Upvotes: 2