Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-07-2010, 07:51 PM   PM User | #1
Leemills
New to the CF scene

 
Join Date: Feb 2010
Location: Norwich
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Leemills is an unknown quantity at this point
Time Of Day/week/hour Message Help

Hi i have been looking everywhere and cant seem time to find anything matching,
what i need is a scheduled message on a website, basically stating days of the week and time and who is live on air. also people maybe on air at 17.30 so i have no idea on how to code this.

e.g

Monday 15th August 17:45 - On Air Now, Lee Mills

so it also refreshes every 1 minute

Thank you for your help.
Leemills is offline   Reply With Quote
Old 02-08-2010, 01:41 AM   PM User | #2
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,797
Thanks: 30
Thanked 462 Times in 456 Posts
jmrker will become famous soon enough
Lightbulb Consider this ...

Different forum, but a similar question has been posed and resolved here.
See: http://www.webdeveloper.com/forum/sh...schedule+times

Maybe it will help with your problem as well.

Good Luck!
jmrker is offline   Reply With Quote
Old 02-08-2010, 07:22 AM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,102
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Here is something I concocted, and which includes an image of the appropriate DJ :-

Code:
<span id = "dj" style="font-size:30px; font-weight:700; font-family:  Arial,Verdana, 
           sans-serif; color: '#FF8000';"></span><img src = "One.gif" id = "theImage">

<script type = "text/javascript"> 
var show = "No show scheduled at present";
var GMToffset = -5;  // Your current GMT offset, whether Standard or Daylight	
var now = new Date();
var dy = now.getDay(); // day of week 0-6
now.setHours(GMToffset + now.getHours() + now.getTimezoneOffset() / 60);
var hh = now.getHours();

// The GMT offset ensures that every visitor, regardless of their timezone, will see the schedule
// that is appropriate for the site owner's local time.

// Tip - for testing purposes you can put here
//dy = 5;
//hh = 9;
// or whatever to check that the right show appears at that day/time.

if (dy >=1 && dy <=5) { // days in Javascript are 0 Sunday - 6 Saturday
if (hh >=5 && hh <9) {show = "The Tom Joyner Morning Show";  document.getElementById("theImage").src = "Four.gif"}
if (hh >=9 && hh <14) {show = "Carl T"; document.getElementById("theImage").src = "Two.gif"}
}

if (dy >=1 && dy <=5) {
if (hh >=14 && hh <=18) {show ="Tommy C"}
}

if (dy >= 1 && dy <=4) {
if (hh >=18 && hh <23) {show = "Keith Sweat"}
}

if (dy == 5) {
if (hh >=18 && hh <=23) {show = "G.L.Haywood (House Party)"}  //goes on to midnight
}

if (dy == 6) { // Saturday Note the two = signs to mean equals
if (hh >= 6 && hh <9) {show = "The Tom Joyner Morning Show: Right Back At Cha!" }
if (hh >= 9 && hh <14) {show = "Carl T"}
if (hh >=14 && hh <20) {show = "George Fisher"}
if (hh >=20 && hh <22) {show = "Chief Chris Omigee & Momanite Nurse"}
if (hh >=22 && hh <24) {show = "House Party"}
} //End of Saturday Shows

if (dy == 0) { //Sunday Shows
if (hh >= 5 && hh <10) {show = "Porshe Evans (Gospel)"}
if (hh >=10 && hh <12) {show = "The Cravins Brothers Zydeco and Info Show with Charles & Donald Cravins"}
if (hh >=12 && hh <17) {show = "George Fisher"}
if (hh >=17 && hh <21) {show = "Dr. Boogie Live"}
}  // End of Sunday Shows

var a = "On air now:-  " + show + " \u00A0 \u00A0 \u00A0 \u00A0 ";  // spaces must be separted by Unicode spaces to prevent collapse
document.getElementById("dj").innerHTML = a;
</script>

To update every minute wrap the whole thing in a function named display(),
then:-
<body onload = "display()">
and at the end of the function:-
setTimeout("display()", 60000); // every 60 seconds
}
</script>


You can use any simple clock script to display the date and time.


At least once per year, some group of scientists will become very excited and announce that whatever they announced last year about global warming is wrong.

Last edited by Philip M; 02-08-2010 at 08:29 AM..
Philip M is offline   Reply With Quote
Old 02-08-2010, 09:08 PM   PM User | #4
Leemills
New to the CF scene

 
Join Date: Feb 2010
Location: Norwich
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Leemills is an unknown quantity at this point
Thank you, quick one how do you change the pictures i didn't get that part however thank you for you help
Leemills is offline   Reply With Quote
Old 02-08-2010, 09:53 PM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,102
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by Leemills View Post
Thank you, quick one how do you change the pictures i didn't get that part however thank you for you help

EXAMPLE:-
if (hh >=9 && hh <14) {show = "Carl T"; document.getElementById("theImage").src = "Two.gif"}
}
Philip M is offline   Reply With Quote
Old 02-08-2010, 10:11 PM   PM User | #6
Leemills
New to the CF scene

 
Join Date: Feb 2010
Location: Norwich
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Leemills is an unknown quantity at this point
that went way over my head.. sorry, also what if a show is on at 17.30?

sorry to be lame i do appreciate it
Leemills is offline   Reply With Quote
Old 02-08-2010, 10:29 PM   PM User | #7
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,102
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by Leemills View Post
that went way over my head.. sorry, also what if a show is on at 17.30?

sorry to be lame i do appreciate it
In that case you will need to extend the script to take account of minutes.

var hh = now.getHours();
var mn = now.getMinutes();

and then convert the minutes to a decimal of an hour (e.g. 15 minutes is .25,
45 minutes is .75 and so on) and add to hh. (e.g. hh = 14 + .5 = 14.5 (hours) = 14.30).

hh = hh + (mn/60);

Then:-

if (hh >=9 && hh <14.5) {show = "Carl T"; document.getElementById("theImage").src = "Two.gif"} // This DJ on from 0900 - 1430


theImage is naturally an image of the relevant DJ. Here it might be CarlT.jpg.

But I have the idea that you are trying to run before you can walk.

Last edited by Philip M; 02-08-2010 at 10:42 PM..
Philip M is offline   Reply With Quote
Old 02-08-2010, 10:40 PM   PM User | #8
Leemills
New to the CF scene

 
Join Date: Feb 2010
Location: Norwich
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Leemills is an unknown quantity at this point
i guess i am, but you and your code is helping me understand it, i thank you for that
Leemills is offline   Reply With Quote
Old 03-29-2011, 07:41 AM   PM User | #9
dspurg7310
New to the CF scene

 
Join Date: Apr 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
dspurg7310 is an unknown quantity at this point
Could you possibly write a full script (like your initial script above) that includes all the changes needed to include minutes. I am trying to make these changes to the script on my website and I am getting all kinds of different results that are not adding up to me. My time zone is -7 Mountain Time also.

Is the
var mn = now.getMinutes();

the only thing you have to add to the top under the hour line or do you have to do something to this line:

now.setHours(GMToffset + now.getHours() + now.getTimezoneOffset()/ 60);

and then do you have to change anything on one of the standard lines such as this one:

if (hh >=17 && hh <21) {show = "Dr. Boogie Live"}

I'm not real familiar with this type of script so I appreciate any help. I am more used to simple HTML but I absolutely LOVE this script and it's EXACTLY what I have been looking for as well!

Thank you in advance for any and all help!
-David.
dspurg7310 is offline   Reply With Quote
Old 03-29-2011, 07:50 AM   PM User | #10
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,102
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by dspurg7310 View Post
Could you possibly write a full script (like your initial script above) that includes all the changes needed to include minutes.
Thank you in advance for any and all help!
-David.
No. What did your last servant die of? The forum is not a free coding service. I explained how to handle minutes in Post #7.

BTW, the time to say "thanks" is afterwards, not beforehand which gives the - doubtless unintended - impression that you take other people's voluntary unpaid assistance and expertise for granted.
Philip M is offline   Reply With Quote
Old 04-02-2011, 12:20 AM   PM User | #11
rgy
New to the CF scene

 
Join Date: Apr 2011
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
rgy is an unknown quantity at this point
That's a really cool script!

When you say "add to hh" followed by hh = hh + (mn/60);
does that code need to be added to var hh = now.getHours();
or now.setHours(GMToffset + now.getHours() + now.getTimezoneOffset() / 60);
?

I tried changing this
now.setHours(GMToffset + now.getHours() + now.getTimezoneOffset() / 60);

to

now.setHours(GMToffset + now.getHours() + now.getTimezoneOffset() mn / 60);
and got a javascript error on load and it didn't seem to take account of the minutes
rgy is offline   Reply With Quote
Old 04-02-2011, 08:07 AM   PM User | #12
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,102
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Code:
var hh = now.getHours();
var mn = now.getMinutes();
hh = hh + (mn/60);
so for example 14:15 becomes 14.25 hours.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
Philip M is offline   Reply With Quote
Old 04-02-2011, 09:21 PM   PM User | #13
rgy
New to the CF scene

 
Join Date: Apr 2011
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
rgy is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
Code:
var hh = now.getHours();
var mn = now.getMinutes();
hh = hh + (mn/60);
so for example 14:15 becomes 14.25 hours.
Of course lol it was that simple. I was trying to make big thing out of it and change other portions of the script. That's really cool! Works perfect! Thank you so much for setting that straight for me!

A lot of other websites have "time of day" scripts but they all just display a message like, Good Morning, Good Afternoon, Good Evening, and Good Night. Plus they don't include the time offset and minutes so they really suck. This script is a lot more elaborate and like Leemills up there, you are helping me understand this stuff too! Thanks again!
rgy is offline   Reply With Quote
Old 04-14-2011, 06:08 AM   PM User | #14
rgy
New to the CF scene

 
Join Date: Apr 2011
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
rgy is an unknown quantity at this point
I have been using this script for a short while now and it was working ok until the time got to midnight, I then learned that you must use 0 instead of 24 to represent the 12am hour. After I got past that short dilemma, now the script works fine until 11pm and will not display the proper information for the 11pm hour. I thought changing the midnight number from 24 to 0 might have messed with it so I changed it back a forth a few times and still no fix. Is there anything I can do to fix this? I wonder if it has anything to do with an error in internet time or something?
rgy is offline   Reply With Quote
Old 04-14-2011, 07:45 AM   PM User | #15
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,102
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
No, there is no error in internet time.

Midnight is 0000 hours. 11.00pm is 23:00 hours.

Without seeing your code it is impossible to say what the problem is, but the fault, dear Brutus, lies not in the stars but ....

Post your relevant code. It should look something like

if (hh >= 23) { show = whatever
Philip M is offline   Reply With Quote
Reply

Bookmarks

Tags
lee, message, mills, schedule, time of day

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 Jump


All times are GMT +1. The time now is 11:04 AM.


Advertisement
Log in to turn off these ads.