Here is my sample data
$(function(){
$('#slider-date').noUiSlider({
behaviour: 'drag',
connect: true,
range: {
'min': timestamp('2015-03-08 11:52:30'),
'max': timestamp('2015-03-09 11:52:02')
},
// Steps of one week
step: 7 * 24 * 60 * 60 * 1000,
// Two more timestamps indicate the handle starting positions.
start: [ timestamp('2015-03-08 11:52:30'), timestamp('2015-03-09 13:29:34') ],
// No decimals
format: wNumb({
decimals: 0
})
});
$("#slider-date").Link('lower').to($("#event-start"), setDate);
$("#slider-date").Link('upper').to($("#event-end"), setDate);
// Create a new date from a string, return as a timestamp.
function timestamp(str){
return new Date(str).getTime();
}
// Create a list of day and monthnames.
var
weekdays = [
"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday",
"Saturday"
],
months = [
"January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December"
];
// Append a suffix to dates.
// Example: 23 => 23rd, 1 => 1st.
function nth (d) {
if(d>3 && d<21) return 'th';
switch (d % 10) {
case 1: return "st";
case 2: return "nd";
case 3: return "rd";
default: return "th";
}
}
// Create a string representation of the date.
function formatDate ( date ) {
console.log(date.getDate());
return weekdays[date.getDay()] + ", " +
date.getDate() + nth(date.getDate()) + " " +
months[date.getMonth()] + " " +
date.getFullYear();
}
// Write a date as a pretty value.
function setDate( value ){
return $(this).html(formatDate(new Date(+value)));
}
});
This is the plugin page and where I got the code structure from http://refreshless.com/nouislider/examples/#section-dates
In the example they provided a year as the start/end min/max. I am providing a timestamp. May be the issue. Not sure.
Here is a screenshot of my console where the error is happening. It is performing the check on the 2015-03-08
date during the error, which is a Sunday which corresponds to 0
. Not sure what the problem is.
$("#slider-date").Link('lower').to($("#event-start"), setDate)
does. But it might callsetDate
which will callformatDate
before assigning the value toweekdays
. - Oriol