...

View Full Version : var anchortime (time+date help)



batty007
12-25-2007, 07:23 AM
G'day all,

Been trying to suss it out for days but with no luck.... I need to find the javascript of this code (below) before its processed....


<script type="text/javascript">
<!--
var anchortime = "Thursday,13,37,+1100";
-->
</script>

Obviously it displays the current day/time of the pageload, and displays a certain header depending on the time of day....

The javascript file it draws the info from is this one (below):


function onairnow(shows,schedule,anchortime) {
var tempShowInfo = false;
/* getters and setters */

this.getShowInfo = function(id) {
for(i=0; i<this.shows.shows.length; i++) {
if(this.shows.shows[i].id == id) {
tempShowInfo = this.shows.shows[i];
}
}

return tempShowInfo;
} // end

this.setShows = function(shows) {
this.shows = shows;
} // end set shows

this.setSchedule = function(shedule) {
this.schedule = shedule;
} // end set schedule

this.getSchedule = function(day) {
if(day) {
return this.schedule[day];
} else {
return this.schedule;
}
} // getSchedule()


this.getListenLive = function() {
return this.listenlive;
} // getListenLive()

this.setListenLive = function(listenlive) {
this.listenlive = listenlive;
} // getListenLive()

this.setAnchorTime = function() {
// anchor time is an array with the hour, minute and day...
this.arr_anchorTime = this.calculateAnchorTime();

} // end setAnchorTime

this.getAnchorTime = function() {
return this.arr_anchorTime;
} // end getAnchorTime

this.getCurrentShow = function() {
showIndex = this.currentShow(this.getStationTime(),this.getToday());
tempSchedule = this.getSchedule(this.getToday());
return tempSchedule[showIndex];
} // end getCurrentShow


/* reach is used if you want to get shows that are further into the future than the next */
this.getNextShow = function(reach) {
/* default back to 1 if no reach is set */
if(!reach) {
reach = 1;
}
tempNextShow = false;
showIndex = this.currentShow(this.getStationTime(),this.getToday());
showIndex = showIndex + reach;
tempSchedule = this.getSchedule(this.getToday());

/*
if the show index is larger than the amount of shows in the day
the next show must be on the next day
*/

if(showIndex >= tempSchedule.length) {
/* switch to the first show of tomorrow */
tempSchedule = this.getSchedule(this.getTommorrow(this.getToday()));
tempNextShowIndex = 0 + (reach - 1);
tempNextShow = tempSchedule[tempNextShowIndex];
} else {
tempNextShow = tempSchedule[showIndex];
}

return tempNextShow;

} // end getNextShow()


/*
Set station time uses the anchor time combined with the
offset to work out what part of the schedule should be used
*/
this.setStationTime = function(arr_time,offset) {

var time = arr_time['hours'] + "" + arr_time['minutes'];

var timeminutes = this.convertSchedTime(time);

tempStationTime = timeminutes + offset;

/*
if the station time is over midnight, we've spilled over to
tomorrow...
*/
if(tempStationTime > 1440) {
tempStationTime = tempStationTime - 1440;
this.setToday(this.getTommorrow(arr_time['day']));
} else if(tempStationTime < 0000) {

tempStationTime = tempStationTime + 1440;
this.setToday(this.getYesterday(arr_time['day']));
} else {
this.setToday(arr_time['day']);
}

this.stationTime = tempStationTime;

return;

} // emd setStationTime



this.getStationTime = function() {
return this.stationTime;
} // end getStationTime

this.getToday = function() {
return this.today;
} // end getToday


this.setToday = function(day) {
this.today = day;

return;
} // end getToday

this.getTommorrow = function(today) {

var tomorrowKey;

for(i=0;i<=this.days.length;i++) {
if(this.days[i] == today) {
/*
we've got the index for today... so increment the index and return
unless the increment puts us out of range... then we go back to the first
day element...
*/

tomorrowKey = i + 1;

if(tomorrowKey > this.days.length) {
tomorrow = this.days[0];
break;
} else {
tomorrow = this.days[tomorrowKey];
break;
}
} // end if day element = today
} // end for loop

return tomorrow;

} // end getTommorrow

this.getYesterday = function(today) {

var yesterdayKey;

for(i=0;i<=this.days.length;i++) {
if(this.days[i] == today) {
/*
we've got the index for today... so increment the index and return
unless the increment puts us out of range... then we go back to the first
day element...
*/

yesterdayKey = i - 1;

if(yesterdayKey < 0) {
yesterday = this.days[this.days.length];
break;
} else {
yesterday = this.days[yesterdayKey];
break;
}
} // end if day element = today
} // end for loop

return yesterday;

} // end getYesterday

/* general methods that shouldn't be accessed directly
takes time as minutes from the day specificied...

*/
this.currentShow = function(time, day) {
/* loop through the current day to find the show... */
var shows = this.shows.shows;
var tempShow = false;
var tempShowFallback = false;

var tempSchedule = this.getSchedule(day);
var tempEndTime;
var tempShowID = false;
var listenlive;

for(i=0;i<tempSchedule.length;i++) {
/* convert end time to minutes */
tempEndTime = this.convertSchedTime(tempSchedule[i].endtime);

if(tempEndTime > time) {
tempShowID = i;
break;
} // end if
} // end for

/*alert("Temp end time: " + tempEndTime + " tempShowID:" + tempShowID + " time:" + time);*/

return tempShowID;

} // end currentShow()

this.setDays = function() {
this.days = new Array( 'Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday' );
return;
}

this.convertAnchorTime = function(anchortime) {
var tempArr_anchortime = anchortime.split(',');
var arr_anchorTime = new Array;

arr_anchorTime['day'] = tempArr_anchortime[0];
arr_anchorTime['hours'] = tempArr_anchortime[1];
arr_anchorTime['minutes'] = tempArr_anchortime[2];

return arr_anchorTime;
} // end

this.convertSchedOffset = function(offset) {
var minutes = 60 * offset;

return minutes;
} // convertSchedOffset();

this.convertSchedTime = function(time) {
/* take the first two digits */
time = time + "";
var hours = parseFloat(time.substring(0,2));
var minutes = parseFloat(time.substring(2,4));
var totalminutes = (60 * hours) + minutes;
return totalminutes;
} // convert sched time


/* CONSTRUTOR STUFF */
var stationTime;
var shows; // this is an object that comes in from a separate data source
var schedule; // this is an object that comes in from a separate data source
var scheduleToday;
var currentShowIndex;

var arr_anchorTime;
this.setDays(); // initialises the days array to help work out what day it is from today...

if(!anchortime) {
// default to GMT via Javascript if the
this.setAnchorTime();
} else {
this.arr_anchorTime = this.convertAnchorTime(anchortime);
}

this.setShows(shows);
this.setSchedule(schedule);
this.setListenLive(this.schedule.listenlive);
this.setStationTime(this.getAnchorTime(),this.convertSchedOffset(this.schedule.timeoffset));
} // end class

function render_listen_live(listenlive) {
var html = '';
html += '<a href="' + listenlive + '" class="listen_live">Listen Live</a>';
return html;
} // function render_listen_live()

/*function render_onair_show_info(oanShowInfo,headertext) {
var html = '';

html += '<h3>' + headertext + '</h3><p>';

if(oanShowInfo.url) {
html += '<a href="' + oanShowInfo.url + '">';
html += oanShowInfo.shortname;
html += '</a>';
} else {
html += oanShowInfo.shortname;
} // end if/else

html += '</p><ul>';
if(oanShowInfo.linkpodcast) {
html += '<li class="podcast"><a href="'+ oanShowInfo.linkpodcast +'">Podcast</a></li>';
} else {
html += '<li class="podcast"><a href="/podcasts/all_shows">Podcast</a></li>';
}
html += '<li class="email"><a href="' + oanShowInfo.linkemail + '">Email the Team</a></li>';
html += '</ul>';

return html;

}*/

function render_onair_show_info(oanShowInfo,headertext) {
var html = '';

html += '<h3>' + headertext + '</h3><p>';

if(oanShowInfo.url) {
html += '<a href="' + oanShowInfo.url + '">';
html += oanShowInfo.shortname;
html += '</a>';
} else {
html += oanShowInfo.shortname;
} // end if/else

html += '</p>';

html += '<a href="' + oanShowInfo.linkemail + '" class="normal">Email the team</a>';

return html;
}

function renderShowInfo(showInfo,introtext,livefeed,additionalhtml) {
var html = '<div class="promo50">';
html += additionalhtml;
html += '<a href=' + showInfo.url + '><img src="' + showInfo.image + '" alt="' + showInfo.name + '" width="50" height="50" /></a>';
html += '<h3><a href=' + showInfo.url + '><strong>' + introtext + '</strong> &ndash; ' + showInfo.name + '</a></h3>';
html += '<p>' + showInfo.description + '</p>';
html += '<ul class="audiolinks">';
if(showInfo.linkpodcast) {
html += '<li class="podcast"><a href="' + showInfo.linkpodcast + '" class="first">Podcast</a></li>';
}

if(livefeed) {
html += '<li class="listen"><a href="/listen/listen_live" class="first"><strong>Listen Now</strong></a></li>';
}
html += '</ul>';
html += '</div>';
return html;
}


var oan = new onairnow(onairnowShows, onairnowSchedule, anchortime);

oanShow = oan.getCurrentShow();
oanShowInfo = oan.getShowInfo(oanShow.id);

oanShowNext = oan.getNextShow();
oanShowNextInfo = oan.getShowInfo(oanShowNext.id);

oanShowLater = oan.getNextShow(2);
oanShowLaterInfo = oan.getShowInfo(oanShowLater.id);

$("#header_container").ready(function() {
$('#header_onairnow_show').html(render_onair_show_info(oanShowInfo,'On Air Now:'));
$('#header_onairnext_show').html(render_onair_show_info(oanShowNextInfo,'On Air Next:'));
$('#header_listenlive').html(render_listen_live(oan.getListenLive()));
});

$(function(){
$('#header_onairnow_show').fadeIn('fast');
$('#header_onairnext_show').fadeIn('fast');
$('#header_listenlive').fadeIn('fast');
});

Sorry about all the code.... But if anyone could work out what the code is I need to type into the index file in order to get the day/time from the above file, I would really appreciate it!!

Many thanks!!

Philip M
12-25-2007, 09:51 AM
Could you explain what is meant by "anchor time" if it is something other than the current date/time?

I don't really understand what you mean by:-

I need to find the javascript of this code (below) before its processed....

The variable anchortime is manipulated in this part of the code:-

this.convertAnchorTime = function(anchortime) {
var tempArr_anchortime = anchortime.split(',');
var arr_anchorTime = new Array;

arr_anchorTime['day'] = tempArr_anchortime[0];
arr_anchorTime['hours'] = tempArr_anchortime[1];
arr_anchorTime['minutes'] = tempArr_anchortime[2];

return arr_anchorTime;
} // end

batty007
12-25-2007, 11:41 AM
I have no idea I am sorry....

I'm not brilliant at coding.... I'm basically trying to design a website for my uncle, and want to use the above javascript off a website which displays different headers at different times....

When I go to the site I want to use, and check the source, the javascript has already been processed "im not sure if thats the correct term" with the "var anchortime "day,hour,minute,GMT""

I basically just need to know what javascript to write in my index page so that it displays the "var anchortime "date,hour,minute,GMT" before its worked out on the page load......

Sorry to be so confusing.... Ive never seen var anchortime either, which is why i needed the help.....

thanks so much for the quick reply!! merry xmas!!

Philip M
12-26-2007, 10:48 AM
Still not entirely sure what you want, but place this right after the <body> tag:-

<script type="text/javascript">

var now = new Date();
var hh = now.getHours();
var mm = now.getMinutes();
var ss = now.getSeconds();
var tim = "Hello! ";
tim = tim + "The time now is " + hh + ":" + mm + ":" +ss ;
document.write(tim);

</script>

batty007
12-27-2007, 12:50 AM
Thanks again for getting back to me, but unfortunately this still doesn't work....

I'll try and explain it abit better....

The website "www.2dayfm.com.au" uses the below code to get the info for it's header text. i.e. whos on air and whos coming up next....



<script type="text/javascript">
<!--
var anchortime = "Thursday,10,10,+1100";

-->
</script>


which displays the "day,hour,minute,+GMT" - and it looks like it gets this info by going to this file....



<script src="http://images.2dayfm.com.au/__data/assets/text_file/0005/6476/site.js" type="text/javascript"></script>


which looks like this:



function onairnow(shows,schedule,anchortime) {
var tempShowInfo = false;
/* getters and setters */

this.getShowInfo = function(id) {
for(i=0; i<this.shows.shows.length; i++) {
if(this.shows.shows[i].id == id) {
tempShowInfo = this.shows.shows[i];
}
}

return tempShowInfo;
} // end

this.setShows = function(shows) {
this.shows = shows;
} // end set shows

this.setSchedule = function(shedule) {
this.schedule = shedule;
} // end set schedule

this.getSchedule = function(day) {
if(day) {
return this.schedule[day];
} else {
return this.schedule;
}
} // getSchedule()


this.getListenLive = function() {
return this.listenlive;
} // getListenLive()

this.setListenLive = function(listenlive) {
this.listenlive = listenlive;
} // getListenLive()

this.setAnchorTime = function() {
// anchor time is an array with the hour, minute and day...
this.arr_anchorTime = this.calculateAnchorTime();

} // end setAnchorTime

this.getAnchorTime = function() {
return this.arr_anchorTime;
} // end getAnchorTime

this.getCurrentShow = function() {
showIndex = this.currentShow(this.getStationTime(),this.getToday());
tempSchedule = this.getSchedule(this.getToday());
return tempSchedule[showIndex];
} // end getCurrentShow


/* reach is used if you want to get shows that are further into the future than the next */
this.getNextShow = function(reach) {
/* default back to 1 if no reach is set */
if(!reach) {
reach = 1;
}
tempNextShow = false;
showIndex = this.currentShow(this.getStationTime(),this.getToday());
showIndex = showIndex + reach;
tempSchedule = this.getSchedule(this.getToday());

/*
if the show index is larger than the amount of shows in the day
the next show must be on the next day
*/

if(showIndex >= tempSchedule.length) {
/* switch to the first show of tomorrow */
tempSchedule = this.getSchedule(this.getTommorrow(this.getToday()));
tempNextShowIndex = 0 + (reach - 1);
tempNextShow = tempSchedule[tempNextShowIndex];
} else {
tempNextShow = tempSchedule[showIndex];
}

return tempNextShow;

} // end getNextShow()


/*
Set station time uses the anchor time combined with the
offset to work out what part of the schedule should be used
*/
this.setStationTime = function(arr_time,offset) {

var time = arr_time['hours'] + "" + arr_time['minutes'];

var timeminutes = this.convertSchedTime(time);

tempStationTime = timeminutes + offset;

/*
if the station time is over midnight, we've spilled over to
tomorrow...
*/
if(tempStationTime > 1440) {
tempStationTime = tempStationTime - 1440;
this.setToday(this.getTommorrow(arr_time['day']));
} else if(tempStationTime < 0000) {

tempStationTime = tempStationTime + 1440;
this.setToday(this.getYesterday(arr_time['day']));
} else {
this.setToday(arr_time['day']);
}

this.stationTime = tempStationTime;

return;

} // emd setStationTime



this.getStationTime = function() {
return this.stationTime;
} // end getStationTime

this.getToday = function() {
return this.today;
} // end getToday


this.setToday = function(day) {
this.today = day;

return;
} // end getToday

this.getTommorrow = function(today) {

var tomorrowKey;

for(i=0;i<=this.days.length;i++) {
if(this.days[i] == today) {
/*
we've got the index for today... so increment the index and return
unless the increment puts us out of range... then we go back to the first
day element...
*/

tomorrowKey = i + 1;

if(tomorrowKey > this.days.length) {
tomorrow = this.days[0];
break;
} else {
tomorrow = this.days[tomorrowKey];
break;
}
} // end if day element = today
} // end for loop

return tomorrow;

} // end getTommorrow

this.getYesterday = function(today) {

var yesterdayKey;

for(i=0;i<=this.days.length;i++) {
if(this.days[i] == today) {
/*
we've got the index for today... so increment the index and return
unless the increment puts us out of range... then we go back to the first
day element...
*/

yesterdayKey = i - 1;

if(yesterdayKey < 0) {
yesterday = this.days[this.days.length];
break;
} else {
yesterday = this.days[yesterdayKey];
break;
}
} // end if day element = today
} // end for loop

return yesterday;

} // end getYesterday

/* general methods that shouldn't be accessed directly
takes time as minutes from the day specificied...

*/
this.currentShow = function(time, day) {
/* loop through the current day to find the show... */
var shows = this.shows.shows;
var tempShow = false;
var tempShowFallback = false;

var tempSchedule = this.getSchedule(day);
var tempEndTime;
var tempShowID = false;
var listenlive;

for(i=0;i<tempSchedule.length;i++) {
/* convert end time to minutes */
tempEndTime = this.convertSchedTime(tempSchedule[i].endtime);

if(tempEndTime > time) {
tempShowID = i;
break;
} // end if
} // end for

/*alert("Temp end time: " + tempEndTime + " tempShowID:" + tempShowID + " time:" + time);*/

return tempShowID;

} // end currentShow()

this.setDays = function() {
this.days = new Array( 'Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday' );
return;
}

this.convertAnchorTime = function(anchortime) {
var tempArr_anchortime = anchortime.split(',');
var arr_anchorTime = new Array;

arr_anchorTime['day'] = tempArr_anchortime[0];
arr_anchorTime['hours'] = tempArr_anchortime[1];
arr_anchorTime['minutes'] = tempArr_anchortime[2];

return arr_anchorTime;
} // end

this.convertSchedOffset = function(offset) {
var minutes = 60 * offset;

return minutes;
} // convertSchedOffset();

this.convertSchedTime = function(time) {
/* take the first two digits */
time = time + "";
var hours = parseFloat(time.substring(0,2));
var minutes = parseFloat(time.substring(2,4));
var totalminutes = (60 * hours) + minutes;
return totalminutes;
} // convert sched time


/* CONSTRUTOR STUFF */
var stationTime;
var shows; // this is an object that comes in from a separate data source
var schedule; // this is an object that comes in from a separate data source
var scheduleToday;
var currentShowIndex;

var arr_anchorTime;
this.setDays(); // initialises the days array to help work out what day it is from today...

if(!anchortime) {
// default to GMT via Javascript if the
this.setAnchorTime();
} else {
this.arr_anchorTime = this.convertAnchorTime(anchortime);
}

this.setShows(shows);
this.setSchedule(schedule);
this.setListenLive(this.schedule.listenlive);
this.setStationTime(this.getAnchorTime(),this.convertSchedOffset(this.schedule.timeoffset));
} // end class

function render_listen_live(listenlive) {
var html = '';
html += '<a href="' + listenlive + '" class="listen_live">Listen Live</a>';
return html;
} // function render_listen_live()

/*function render_onair_show_info(oanShowInfo,headertext) {
var html = '';

html += '<h3>' + headertext + '</h3><p>';

if(oanShowInfo.url) {
html += '<a href="' + oanShowInfo.url + '">';
html += oanShowInfo.shortname;
html += '</a>';
} else {
html += oanShowInfo.shortname;
} // end if/else

html += '</p><ul>';
if(oanShowInfo.linkpodcast) {
html += '<li class="podcast"><a href="'+ oanShowInfo.linkpodcast +'">Podcast</a></li>';
} else {
html += '<li class="podcast"><a href="/podcasts/all_shows">Podcast</a></li>';
}
html += '<li class="email"><a href="' + oanShowInfo.linkemail + '">Email the Team</a></li>';
html += '</ul>';

return html;

}*/

function render_onair_show_info(oanShowInfo,headertext) {
var html = '';

html += '<h3>' + headertext + '</h3><p>';

if(oanShowInfo.url) {
html += '<a href="' + oanShowInfo.url + '">';
html += oanShowInfo.shortname;
html += '</a>';
} else {
html += oanShowInfo.shortname;
} // end if/else

html += '</p>';

html += '<a href="' + oanShowInfo.linkemail + '" class="normal">Email the team</a>';

return html;
}

function renderShowInfo(showInfo,introtext,livefeed,additionalhtml) {
var html = '<div class="promo50">';
html += additionalhtml;
html += '<a href=' + showInfo.url + '><img src="' + showInfo.image + '" alt="' + showInfo.name + '" width="50" height="50" /></a>';
html += '<h3><a href=' + showInfo.url + '><strong>' + introtext + '</strong> &ndash; ' + showInfo.name + '</a></h3>';
html += '<p>' + showInfo.description + '</p>';
html += '<ul class="audiolinks">';
if(showInfo.linkpodcast) {
html += '<li class="podcast"><a href="' + showInfo.linkpodcast + '" class="first">Podcast</a></li>';
}

if(livefeed) {
html += '<li class="listen"><a href="/listen/listen_live" class="first"><strong>Listen Now</strong></a></li>';
}
html += '</ul>';
html += '</div>';
return html;
}


var oan = new onairnow(onairnowShows, onairnowSchedule, anchortime);

oanShow = oan.getCurrentShow();
oanShowInfo = oan.getShowInfo(oanShow.id);

oanShowNext = oan.getNextShow();
oanShowNextInfo = oan.getShowInfo(oanShowNext.id);

oanShowLater = oan.getNextShow(2);
oanShowLaterInfo = oan.getShowInfo(oanShowLater.id);

$("#header_container").ready(function() {
$('#header_onairnow_show').html(render_onair_show_info(oanShowInfo,'On Air Now:'));
$('#header_onairnext_show').html(render_onair_show_info(oanShowNextInfo,'On Air Next:'));
$('#header_listenlive').html(render_listen_live(oan.getListenLive()));
});

$(function(){
$('#header_onairnow_show').fadeIn('fast');
$('#header_onairnext_show').fadeIn('fast');
$('#header_listenlive').fadeIn('fast');
});


so basically, i need to know what to type above the </header> tag in replace of:



<script type="text/javascript">
<!--
var anchortime = "Thursday,10,10,+1100";

-->
</script>


to replace to the wrong day,hour,minute with the correct day,hour,minute that someone loads the page....

so that they can view which dj is currently on-air, and which dj is coming up next..... hope that makes sence...

thanks so much again for your help!!

Philip M
12-27-2007, 08:54 AM
I am still unclear what you mean by the "correct" time of day. Does that mean the actual current time? Are you saying that you want the variable anchortime to be set to the current day, hour and minute in the format Thursday,10,10,+1100? Is +1100 the offset for Australian time vs GMT? Remember that the time is taken from the user's computer (so presumably is more or less accurate in local time) and not from the server.

Try this:-

<script type="text/javascript">

var days = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var months = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var now = new Date();
var dd = now.getDate();
var mn = now.getMonth();
var mon = months[mn];
var day = now.getDay();
var dy = days[day];
var hh = now.getHours(); // hh = hours expressed in local time, or use var hh = now.getUTCHours() for GMT
if (hh <10) {hh = '0' + hh}
var mm = now.getMinutes();
if (mm <10) {mm = '0' + mm}
var ss = now.getSeconds();
if (ss <10) {ss = '0' + ss}
var tim = "Hello! Today is ";
tim = tim + dy + " " + dd + " " + mon + "<br>";
tim = tim + "The time now is " + hh + ":" + mm + ":" +ss ;
document.write(tim);

var anchortime = dy + "," + hh + "," + mm + ",+1100"
alert (anchortime);

</script>

batty007
12-28-2007, 12:19 AM
Legend!

I think that might have done it! Will get back to you this afternoon when the time has moved on to see if it changes!!

I edited out the "alert" and the "write" parts of the script - and it works prefectly like i want it too so far!!

thank you SO much!!

batty007
12-28-2007, 09:58 AM
Works excelent!! Thanks so much again for your time!! Can't tell you how much I appreciate it!! Cheers!!

Philip M
12-28-2007, 10:28 AM
Glad to have helped. To start with I was a bit confused because I thought that anchortime was some sort of time used on radio shows, the time when the anchorman came on or something. :D:D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum