...

View Full Version : Scheduler script - getHours complication



Tom Hogan
12-31-2003, 01:39 PM
Hi all, a colleague and I have been trying to fathom whether there is a solution to this problem, and we'd very much appreciate any help we can get on the matter!

We're running a scheduler script as below:

today = new Date()
day = today.getDay()
hr = today.getHours()

if (day ==1)
{if ((hr ==0) || (hr ==1) || (hr ==2) || (hr ==3) || (hr ==4) || (hr ==5) || (hr ==6) || (hr ==7) || (hr ==8) || (hr ==9) || (hr ==10) || (hr ==11) || (hr ==12) || (hr ==13) || (hr ==14) || (hr ==15) || (hr ==16))
document.write("a")
if ((hr ==17) || (hr ==18))
document.write("b")
if ((hr ==19) || (hr ==20))
document.write("c")
if ((hr ==21) || (hr ==22) || (hr ==23))
document.write("d")}

if (day ==2) etc. etc.

...which is fine if the schedule changes on the hour. Is it at all possible to alter the script so that if the schedule changes on the half hour, the content of the script can as well, as in, for example, at 17:30, so you don't have to wait until 18:00 for the script to change, or have it running early from 17:00?

NanakiXIII
12-31-2003, 01:56 PM
Use minutes. min = today.getMinutes()

Tom Hogan
12-31-2003, 02:02 PM
Right, for it to change at 17:30 then, would it work like this?

today = new Date()
day = today.getDay()
hr = today.getHours()
min = today.getMinutes()

if (day ==1)
{if ((hr ==0) || (hr ==1) || (hr ==2) || (hr ==3) || (hr ==4) || (hr ==5) || (hr ==6) || (hr ==7) || (hr ==8) || (hr ==9) || (hr ==10) || (hr ==11) || (hr ==12) || (hr ==13) || (hr ==14) || (hr ==15) || (hr ==16) || (hr ==17)
document.write("a")
if ((hr ==17) || (min ==30) || (hr ==18))
document.write("b")
if ((hr ==19) || (hr ==20))
document.write("c")
if ((hr ==21) || (hr ==22) || (hr ==23))
document.write("d")}

if (day ==2) etc. etc.

me'
12-31-2003, 02:58 PM
Well first off your script could be a lot shorter:
today = new Date()
day = today.getDay()
hr = today.getHours()
min = today.getMinutes()

switch (today) {
case 1: (hr <= 16) ? document.write('a') :
(hr >= 17 && hr <= 18) ? document.write('b') :
(hr >= 19 && hr <= 20) ? document.write('c') :
(hr >= 21 && hr <= 23) ? document.write('d') : return false;
case 2: //etc.}I'll have a think about your question.

A1ien51
12-31-2003, 03:26 PM
Change all of the numbers in "me'"s code to be hour and ahalf

aka.... 17 would be 17.5

then you can use this code.

min = today.getMinutes()
if(min >= 30)hr +=.5;

Eric

Tom Hogan
12-31-2003, 03:56 PM
Thanks for all your help so far, still can't get it to work though....

This is how I interpreted that code (case 1 being Monday, case 7 Sunday etc.):

today = new Date()
day = today.getDay()
hr = today.getHours()
min = today.getMinutes()
if(min >= 30)hr +=.5;

switch (today) {
case 1: (hr <= 23) ? document.write('a') : return false;
case 2: (hr <= 23) ? document.write('a') : return false;
case 3: (hr <= 23) ? document.write('a') : return false;
case 4: (hr <= 23) ? document.write('a') : return false;
case 5: (hr <= 23) ? document.write('a') : return false;
case 6: (hr <= 23) ? document.write('a') : return false;
case 7: (hr <= 14) ? document.write('a') : return false;
(hr >= 15.5 && hr <= 16) ? document.write('b') :
(hr >= 17 && hr <= 18) ? document.write('c') :
(hr >= 19 && hr <= 20) ? document.write('d') :
(hr >= 21 && hr <= 23) ? document.write('e') : return false;

Tried using it, and it displayed nothing at all - where am I going wrong?

Tom Hogan
01-02-2004, 10:12 PM
Thanks for your help, guys - we sorted the problem.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum