I have a while loop that selects dateCells inclusively that is now breaking due to daylight saving coming up and i'm wondering if there's a better way of fixing it.. (my plan is below the code)
function doLoop(startDateObj, endDateObj){
console.log("start: " + startDateObj)
console.log("end: " + endDateObj)
console.log("-----")
var counterDateObj = new Date(startDateObj);
while (true){
if (counterDateObj.getTime()>endDateObj.getTime()){
// hit! reached after end date
console.log("=> hit");
console.log("counter: "+counterDateObj)
console.log("getTime(): "+counterDateObj.getTime()+" > "+endDateObj.getTime())
break;
};
console.log(counterDateObj);
counterDateObj.setUTCDate(counterDateObj.getUTCDate() + 1);
};
};
Putting values before and after daylight savings throws the entire thing off:
doLoop(new Date('03/07/09'), new Date('03/10/09'));
VM2826:2 start: Sat Mar 07 2009 00:00:00 GMT-0500 (Eastern Standard Time)
VM2826:3 end: Tue Mar 10 2009 00:00:00 GMT-0400 (Eastern Daylight Time)
VM2826:4 -----
VM2826:18 Sat Mar 07 2009 00:00:00 GMT-0500 (Eastern Standard Time)
VM2826:18 Sun Mar 08 2009 00:00:00 GMT-0500 (Eastern Standard Time)
VM2826:18 Mon Mar 09 2009 01:00:00 GMT-0400 (Eastern Daylight Time)
VM2826:11 => hit
VM2826:12 counter: Tue Mar 10 2009 01:00:00 GMT-0400 (Eastern Daylight Time)
VM2826:13 getTime(): 1236661200000 > 1236657600000
My current plan is: if it's greater than endDate timestamp + 5 extra hours in milliseconds, or something similar..
Can anyone think of a better way? My plan seems pretty ehhhh- not good