+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    2

    Arrow how to edit this JS code -DAY OF CYCLE

     
    I have this code on our high school website that displays the day of the cycle, for example "Today is day 3". On the weekends it will say "Monday is day 4". We are changing from an 8 day cycle to a 4 day cycle. What do I need to edit on the code below to switch it from an 8 day to a 4 day cycle?I cannot get in touch with the author as it was a former student. Thanks!


    function cycleday(last, day){
    day = day-1;
    //Set the two dates
    var lday = last;
    today=new Date();
    //Get 1 day in milliseconds
    var one_day=1000*60*60*24;
    //how far from the end of the week that day was
    offset = lday.getDay();
    //get how many weekends since then
    ends = Math.ceil((today.getTime()-lday.getTime())/(one_day));
    ends += offset;
    ends = Math.floor(ends/7);

    //Calculate difference btw the two dates, and convert to days
    d = Math.ceil((today.getTime()-lday.getTime())/(one_day));
    //subtract the weekends
    d = d + day - 1 - ends*2;
    //how many days of the cycle
    d = d%4;

    if (today.getDay() == 0 || today.getDay() == 6){
    d += 2;
    return "Monday is Day " + d;}
    else{
    d += 1;
    return "Today is Day " + d;}
    }

    function cycle(){
    //update if the counter is off
    var lastday = new Date(2010, 4-1, 16); //yyyy, mm-1, dd
    var thatday = 2; //the day of the cycle it was
    document.write("<span class='cycle'>");
    document.write(cycleday(lastday, thatday));
    document.write("</div><br><br>");
    }

  2. #2
    Junior Member
    Join Date
    Aug 2011
    Posts
    2
    to clarify further...
    If "Monday is day 4", the next day Tuesday will be day 1, Wednesday day 2, Thursday is day 3 and Friday would then be day 4. Then the following Monday would be day 1.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Constant on/off cycle
    By DonnaRonna in forum Technical Support
    Replies: 1
    Last Post: July 19th, 2011, 11:50 AM
  2. Can someone help with a code edit ?
    By noxx in forum Webmastering and Programming
    Replies: 0
    Last Post: May 17th, 2011, 01:48 PM
  3. The Galactic Equinox Cycle
    By SiliconJon in forum IMO Community
    Replies: 3
    Last Post: February 6th, 2007, 11:00 AM
  4. Windows Life Cycle
    By Ben Humphreys in forum General Tech Discussion
    Replies: 2
    Last Post: April 4th, 2006, 12:09 PM
  5. Burn: cycle
    By thePh@r@oh in forum General Gaming Discussion
    Replies: 5
    Last Post: November 24th, 2003, 03:30 PM

Tags for this Thread

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Recommended Sites: ResellerRatings Store Reviews