Рассмотрим следующее.
Пример: https://jsfiddle.net/Twisty/2g957zwa/64/
JavaScript
$(function() {
var format = "yy.mm.dd";
var minDate = "2019.05.01";
var maxDate = "2019.07.31";
function formatDate(str) {
var yy = str.slice(0, 4);
var mm = str.slice(5, 7);
var dd = str.slice(8);
var f = yy + "-" + mm + "-" + dd;
console.log("Format:", f);
return f;
}
function strToDate(f, str) {
return $.datepicker.parseDate(f, str);
}
function dateToStr(f, dt) {
return $.datepicker.formatDate(f, dt);
}
function calcDayDiff(a, b) {
var d1 = Date.parse(formatDate(a)),
d2 = Date.parse(formatDate(b)),
tdf = Math.abs(d2 - d1),
ddf = Math.ceil(tdf / (1000 * 3600 * 24));
console.log("Calc:", a, b, d1, d2, tdf, ddf);
return ddf;
}
function addDays(dt, d) {
var nt = d * (1000 * 3600 * 24);
var ndt = new Date(dt.getTime() + nt);
console.log("Add:", dt, d, nt, ndt);
return ndt;
}
function dateToSeconds(dStr) {
var dt = new Date(dStr);
return dt.getTime() / 1000;
}
$("#slider-range").slider({
min: 0,
max: calcDayDiff(minDate, maxDate),
step: 1,
value: calcDayDiff(minDate, "2019.05.27"),
slide: function(event, ui) {
var dtv = addDays(strToDate(format, minDate), ui.value);
$("#date-slider-1").val(dateToStr(format, dtv));
}
});
var sdtv = addDays(strToDate(format, "2019.05.01"), $("#slider-range").slider("value"));
$("#date-slider-1").val(dateToStr(format, sdtv));
var slider1Autoplay = false;
var intv;
console.log("Init: ", slider1Autoplay, $("#slider-range").slider("value"));
$("#slider-1-autoplay").on("click", function() {
slider1Autoplay = (slider1Autoplay) ? false : true;
if (slider1Autoplay == false) {
clearInterval(intv);
}
intv = setInterval(function() {
var cv = $("#slider-range").slider("value");
var sdtv = addDays(strToDate(format, minDate), ++cv);
$("#slider-range").slider("value", cv);
$("#date-slider-1").val(dateToStr(format, sdtv));
}, 1000);
});
});
Надеюсь, это поможет.