-1

My school runs on a 7 day cycle, so if today (2016/02/26) was day 1, tomorrow would be day 0, Monday would be day 2, and the next day 1 would be 2016/03/08. I know it's very strange, but I'm trying to find a way to use the Date object in JavaScript and add on one cycle, that is 7 days, not including weekends.

I would like to emphasize that weekends DO NOT COUNT towards day counting. I'm trying to find a way to omit weekends and easily find the next day 1 or day 5 or whatever.

RetroCraft
  • 327
  • 1
  • 2
  • 13

1 Answers1

0

There are either 1 or 2 weekends in your 7-day school cycle, depending on the start day of the cycle, so the actual cycle length is either 9 or 11 days. The Date.getDay() method gives you access to the day of the week, so a possible solutions might look like this:

var myDate= new Date();
switch(true) {
//Sunday=0, Saturday=6
case(myDate.getDay() % 6 == 0) :  alert('weekend!'); return;
case (myDate.getDay() < 4) :  // Mon, Tues, Wed
    myDate.setDate(myDate.getDate() + 9);
    break;
case (myDate.getDay() < 6) :  // Thu, Fri
    myDate.setDate(myDate.getDate() + 11);
    break;
}
grymlord
  • 42
  • 5