date - Counting weekday cycles in JavaScript -
my school runs on 7 day cycle, if today (2016/02/26) day 1, tomorrow day 0, monday day 2, , next day 1 2016/03/08. know it's strange, i'm trying find way use date
object in javascript , add on 1 cycle, 7 days, not including weekends.
i emphasize weekends not count towards day counting. i'm trying find way omit weekends , find next day 1 or day 5 or whatever.
there either 1 or 2 weekends in 7-day school cycle, depending on start day of cycle, actual cycle length either 9 or 11 days. date.getday() method gives access day of week, possible solutions might 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; }
Comments
Post a Comment