Javascript array of dates - not iterating properly (jquery ui datepicker)

Posted by PaulB on Stack Overflow See other posts from Stack Overflow or by PaulB
Published on 2010-03-23T20:22:14Z Indexed on 2010/03/23 20:23 UTC
Read the original article Hit count: 264

Filed under:
|
|
|
|

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>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about array