Javascript array of dates - not iterating properly (jquery ui datepicker)
- by PaulB
Hi
I have some code which builds an array of date ranges. I then call a function, passing it a date, and compare that date with dates in the array. I'm doing it this way because the dates are stored in a cms, and I'm manipulating the JqueryUI datepicker.
Unfortunately my code only checks the first date range in the array - and I can't figure out why! I think it's probably something simple (/stupid!) - if anyone can shed some light on it I'd be extremely grateful!
The code is below - the june-september range works fine, the december to jan is totally ignored...
<script type="text/javascript" language="javascript">
var ps1 = new Date(2010, 06-1, 18);
var pe1 = new Date(2010, 09-1, 03);
var ps2 = new Date(2010, 12-1, 20);
var pe2 = new Date(2011, 01-1, 02);
var peakStart = new Array(ps1,ps2);
var peakEnd = new Array(pe1,pe2);
function checkDay(date) {
var day = date.getDay();
for (var i=0; i<peakStart.length; i++) {
if ((date > peakStart[i]) && (date < peakEnd[i])) {
return [(day == 5), ''];
} else {
return [(day == 1 || day == 5), ''];
}
}
}
</script>