Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com mawha

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 08-28-2011, 02:02 AM PM User | #1 kmaw New to the CF scene   Join Date: Aug 2011 Posts: 7 Thanks: 0 Thanked 0 Times in 0 Posts mawha 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? 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(""); document.write(cycleday(lastday, thatday)); document.write("

"); }
08-28-2011, 02:08 AM   PM User | #2
webdev1958
Banned

Join Date: Apr 2011
Posts: 656
Thanks: 14
Thanked 69 Times in 69 Posts
Quote:
 Originally Posted by kmaw What do I need to edit on the code below to switch it from an 8 day to a 4 day cycle? Thanks!
Did you ask the person who wrote the code and if so, what did they say?

Last edited by webdev1958; 08-28-2011 at 02:13 AM..

 08-28-2011, 02:13 AM PM User | #3 kmaw New to the CF scene   Join Date: Aug 2011 Posts: 7 Thanks: 0 Thanked 0 Times in 0 Posts it was a former student who am no longer in contact with.
08-28-2011, 02:57 AM   PM User | #4
jmrker
Senior Coder

Join Date: Aug 2006
Location: FL
Posts: 2,935
Thanks: 36
Thanked 477 Times in 471 Posts

Quote:
 Originally Posted by kmaw 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? Thanks!
Can you expand on the description of the change?

For example, if you start with "Monday is day 4", will the next day Tuesday be day 1 and Wednesday be day 2 and Thursday is day 3 and Friday then be day 4?
Will that make the following Monday as day 1 in that particular cycle.

What date (not day) is the start of a cycle? Is this always the same year after year or does it change from semester to semester?

 08-28-2011, 03:05 AM PM User | #5 kmaw New to the CF scene   Join Date: Aug 2011 Posts: 7 Thanks: 0 Thanked 0 Times in 0 Posts Yes that is correct it just runs in a continuous cycle from day 1 to 4 just as you wrote. At times with storms days and holidays I would just go in and adjust the line near the bottom to reset the day if it was out of sync. here is the part for the reset... //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(""); document.write(cycleday(lastday, thatday)); document.write("

"); }
 08-28-2011, 06:24 AM PM User | #6 jmrker Senior Coder     Join Date: Aug 2006 Location: FL Posts: 2,935 Thanks: 36 Thanked 477 Times in 471 Posts Major modification alert... Try out this version and see how close I have come to the requirements. Note, for testing purposes I have modified the start date to Aug 1, 2011 as cycle 1. Hopefully it is a bit easier to comprehend than the previous code. Code: ``` Untitled ```
 08-28-2011, 02:59 PM PM User | #7 kmaw New to the CF scene   Join Date: Aug 2011 Posts: 7 Thanks: 0 Thanked 0 Times in 0 Posts Wow that's great, I'm sure your script will do the trick. I am having some trouble getting it positioned on the site however. Here is the website with the old 8 day cycle. In the index page the line calls on the day.js file that I had posted yesterday.You can see it here. http://www.cec.ccrsb.ca/ -------------------------------------------------------------------- Here is the page with your script http://www.cec.ccrsb.ca/index4day.html In this case the linecalls on the code that you wrote which I have saved in a js file. The script seems to be causing some problems. Do you see anything obvious that I am doing wrong, Should I just be swapping out the code in the js file like that? thanks so much!
 08-28-2011, 03:50 PM PM User | #8 kmaw New to the CF scene   Join Date: Aug 2011 Posts: 7 Thanks: 0 Thanked 0 Times in 0 Posts Actually the script is not causing any problems, I just need to figure out how to correct the formatting to make the text white and on its own line as it was in the 8 day cycle.
08-28-2011, 04:08 PM   PM User | #9
jmrker
Senior Coder

Join Date: Aug 2006
Location: FL
Posts: 2,935
Thanks: 36
Thanked 477 Times in 471 Posts

Quote:
 Originally Posted by kmaw Actually the script is not causing any problems, I just need to figure out how to correct the formatting to make the text white and on its own line as it was in the 8 day cycle.
Change the style of the "cycle" display
Code:
```<style type="text/css">
.cycle { font-family:monospace; }
</style>```
You can change the font-family, or leave it as default if you delete it.
You can change the color with color:white;
There are a lot more things you can do with the CSS style, including positioning, backgrounds, emphasis, etc.
You should not need to change the JS at all if it is working correctly for you.

 08-28-2011, 05:49 PM PM User | #10 kmaw New to the CF scene   Join Date: Aug 2011 Posts: 7 Thanks: 0 Thanked 0 Times in 0 Posts thanks jmrker It's all working now. Thanks so much for taking the time to share your knowledge with me. I really appreciate your help!
08-28-2011, 09:16 PM   PM User | #11
jmrker
Senior Coder

Join Date: Aug 2006
Location: FL
Posts: 2,935
Thanks: 36
Thanked 477 Times in 471 Posts

Quote:
 Originally Posted by kmaw It's all working now. Thanks so much for taking the time to share your knowledge with me. I really appreciate your help!
You're most welcome.
Happy to help.
Good Luck!

PS: It looks like you forgot your last </span> tag write in your external file.
Code:
```function cycle(){
//update if the counter is off
var lastday = new Date(2011, 8-1, 1); //yyyy, mm-1, dd
var thatday = 0; // the day of the cycle it was (0-3 for 1-4 display)
var today = new Date(2011,8-1,1);
// only command needed
document.write("<span class='cycle'>");
document.write(cycleday(lastday, thatday, new Date()));
document.write('</span>');
}```

Last edited by jmrker; 08-28-2011 at 09:20 PM.. Reason: Recommendation or Observation

 08-28-2011, 10:38 PM PM User | #12 kmaw New to the CF scene   Join Date: Aug 2011 Posts: 7 Thanks: 0 Thanked 0 Times in 0 Posts good eye! thanks. I have added it.

 Bookmarks

 Tags help edit javascript code

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 12:11 PM.