...

View Full Version : I would like a code/script that changes according to the time



Mark Wasley
06-18-2012, 08:32 PM
Here's my scenario:

I'm going on a long distance bus trip up the North Island of New Zealand on 30th June 2012. My time table is below & I want to display something like Mark is in (name of the Town/City) on the Naked Bus.

When I am between places I want to display something like
Mark is between (Town/City I was just at) & (Town/City I will be in next) on the Naked Bus

& if possible Mark will be in (Town/City I will be in next) in X minutes with 'X' being how many minutes to the next Town/City.


TOWN/CITY ARRIVE DEPART
Palmerston North Central 11.30am
Feilding 12.00pm 12.00pm
Hunterville 12.35pm 12.35pm
Taihape 1.10pm 1.45pm
Waiouru 2.10pm 2.10pm
Turangi 2.50pm 2.50pm
Taupo 3.45pm 4.25pm
Tokoroa 5.20pm 5.20pm
Putaruru 5.40pm 5.40pm
Tirau 5.45pm 5.45pm
Cambridge 6.05pm 6.05pm
Hamilton Central 6.30pm 6.30pm
Ngaruawahia 6.50pm 6.50pm
Huntly 7.10pm 7.10pm
Bombay Service Centre 7.40pm 7.40pm
Manakau 7.50pm 7.50pm
Auckland City Central 8.15pm


I would appreciate someone sorting something like this out for me as I do not know a thing about codes & scripts. I would like it in JavaScript though.

Once I know how the code/script is 'written' I can do the return trip back to Palmerston North (which will be on a different day & times will change).

My email address is: webmaster@mark-wasley.exofire.net (mailto:webmaster@mark-wasley.exofire.net)
Please let me know when this is sorted, I really appreciate someone's help.:)

Mark Wasley.

WolfShade
06-18-2012, 08:38 PM
http://www.freelancer.com

Old Pedant
06-18-2012, 09:06 PM
Nice quote! Have to wonder how many people know who Lazarus Long is. Or will be. Or was. Or all of the above.

Old Pedant
06-18-2012, 09:08 PM
You know, this isn't really very complex code. But one has to wonder if it is actually homework for a class. It doesn't seem to have much practical application. How many people are going to be following you on that trip? Why not just use Twitter and post a Tweet as you reach each station? Would surely be more effective than making the 2 or 3 people who are following you look at their browsers.

WolfShade
06-18-2012, 09:11 PM
Nice quote! Have to wonder how many people know who Lazarus Long is. Or will be. Or was. Or all of the above.
I don't know many Heinlein fans. Even fewer who have even heard of Lazarus Long. Sadly.

Old Pedant
06-18-2012, 09:12 PM
Just noticed something. "Long distance bus trip."

Perspective is everything, isn't it?

Less than 8 hours of actual driving time. At what? Let's say 50 mile per hour (80 KPH).

400 miles (640 KM).

Here in USA, that's just a short jaunt. Long distance means over 1500 miles (2400 KM) or so.

<grin/>

Old Pedant
06-18-2012, 09:14 PM
I grew up on Heinlein. If there's any of his later works I missed, I sure don't know what they are. <grin/>

WolfShade
06-18-2012, 09:15 PM
Have you read the UNcut version of Stranger In A Strange Land?

If not, highly recommended. Ginny had it published shortly after his demise. Read it side-by-side with the original published version and convinced the publisher to do it.

Old Pedant
06-18-2012, 09:57 PM
Yes, purchased it 2 or 3 years ago. Amazing how things change in a few short years, no?

WolfShade
06-18-2012, 10:00 PM
Same thing pretty much happened to Tolkein. "No one wants to read a book that thick; split it into three different books." Now you can purchase all three in one volume. Gah.

Old Pedant
06-18-2012, 10:28 PM
LOL! Look at my post #6. Perspective is everything in more ways tham one.

We think that modern people are so tied up in busy lives they don't have time to read, yet novels nowadays are longer than in prior times. Was reading "Under Heaven" by Guy Kay. That's surely a book that would have been split up in years past. Or look at how the size of the Harry Potter books compare to, say, the old Hardy Boy or Nancy Drew series. Even kids are reading more, it would seem.

Maybe people (well some of us <grin/>) really are getting smarter.

Hashim1
06-19-2012, 01:02 AM
LOL! Look at my post #6. Perspective is everything in more ways tham one.

We think that modern people are so tied up in busy lives they don't have time to read, yet novels nowadays are longer than in prior times. Was reading "Under Heaven" by Guy Kay. That's surely a book that would have been split up in years past. Or look at how the size of the Harry Potter books compare to, say, the old Hardy Boy or Nancy Drew series. Even kids are reading more, it would seem.

Maybe people (well some of us <grin/>) really are getting smarter.

Don't count on it. Bigger books are certainly no accurate measure of how "smart" people are: if anything just another by-product of societies where we have to have bigger portions of everything to satisfy our many delights - whether that be food or books. People - adults and children alike - are being dumbed down day by day, unfortunately.

Mark Wasley
06-19-2012, 02:54 AM
Hi Everyone.

I don't know anything about codes & scripts so I am really hoping for someone to help me with my scenario. I used the term 'long distance' so you'll know what I mean ... & so you would all know that I'm not talking about city buses in Palmerston North. I will be trying to post twitter messages so friends & family who visit my website will know 'LIVE' updates - I have put a link to my Twitter on my site. If someone helps me this time, then I'll know what to do next time I need something like this done ( & I can do it myself ).

I look forward to hearing from anybody,

Mark :)

Mark Wasley
06-19-2012, 02:59 AM
You know, this isn't really very complex code. But one has to wonder if it is actually homework for a class. It doesn't seem to have much practical application. How many people are going to be following you on that trip? Why not just use Twitter and post a Tweet as you reach each station? Would surely be more effective than making the 2 or 3 people who are following you look at their browsers.

Hi there,

The code may not be complex but I do not know anything about codes & scripts so I came here hoping for some help.

I will be trying to post twitter messages so friends & family who visit my website will know 'LIVE' updates - I have put a link to my Twitter on my site.

If you (or anyone else) helps me this time, then I'll know what to do next time I need something like this done ( & I can do it myself ).

Thankyou, Mark. :)

xelawho
06-19-2012, 01:38 PM
much as I hate to interrupt a literary discussion, here is a little script that might help you get started:



<body>
<div id="message"></div>
<script type="text/javascript">
var now=new Date();
if (now<new Date("Dec 25, 2013 06:00")){
var mess="not time for presents yet";
}else{
var mess="open 'em up!";
}
document.getElementById("message").innerHTML=mess;
</script>
</body>

Old Pedant
06-19-2012, 09:37 PM
Oh, what the heck. This really was easy.

I've tested this pretty reasonably. I think it works right.



<!DOCTYPE html>
<html>
<body>
<h1>Mark's Bus Ride</h1>
<br/><br/>
<h3 id="message"></h3>

<script type="text/javascript">
var stations = [
['Palmerston North Central','0.00am','11.30am'],
['Feilding','12.00pm','12.00pm'],
['Hunterville','12.35pm','12.35pm'],
['Taihape','1.10pm','1.45pm'],
['Waiouru','2.10pm','2.10pm'],
['Turangi','2.50pm','2.50pm'],
['Taupo','3.45pm','4.25pm'],
['Tokoroa','5.20pm','5.20pm'],
['Putaruru','5.40pm','5.40pm'],
['Tirau','5.45pm','5.45pm'],
['Cambridge','6.05pm','6.05pm'],
['Hamilton Central','6.30pm','6.30pm'],
['Ngaruawahia','6.50pm','6.50pm'],
['Huntly','7.10pm','7.10pm'],
['Bombay Service Centre','7.40pm','7.40pm'],
['Manakau','7.50pm','7.50pm'],
['Auckland City Central','8.15pm','11.59pm']
];

// this function converts "3.11pm" to minutes since midnight
function getTime( txt )
{
var ampm = txt.substring( txt.length - 2 );
var hm = txt.substring( 0, txt.length - 2 ).split(".");
var hr = Number(hm[0]);
var mn = Number(hm[1]);
if ( ampm.charAt(0) == "p" && hr < 12 ) hr += 12;
return hr * 60 + mn;
}

function where( )
{
var msg = document.getElementById("message");

var now = new Date();
// current time as minutes since midnight
var curmin = Math.round(
now.getHours() * 60 + now.getMinutes() + ( now.getSeconds() / 60 ) );

// search through stations to see where we are
var lastFrom = 0;
var lastStation = "Home";

for ( var s = 0; s < stations.length; ++s )
{
var stn = stations[s];
var name = stn[0];
var tfrom = getTime( stn[1] );
var tto = getTime( stn[2] );
if ( curmin >= tfrom && curmin <= tto )
{
// we are AT a station
msg.innerHTML =
"Mark is in " + name + " on the Naked Bus.";
return;
}
else if ( curmin > lastFrom && curmin < tfrom )
{
// we are approaching a station
arrive = tfrom - curmin;
msg.innerHTML =
"Mark is between " + lastStation + " and " + name + " on the Naked Bus.<br/>"
+ "Mark will be in " + name + " in " + arrive + " minutes.";
return;
}
lastStation = name;
lastFrom = tfrom;
}
}
where( );
setInterval( where, 15000 ); // recheck every 15 seconds
</script>
</body>
</html>


Before the ride starts and after it ends, it says you are in the starting/ending stations.

I am not responsible for the bus being off schedule.

******

EDIT: Changed 11:59pm to 11.59pm ... times must use periods to be consistent

Old Pedant
06-19-2012, 09:39 PM
Note: The above script does *NOT* check the date. So you can run it on a test page any time between now and the trip to make sure it's working right.

Note: The script only works as-is in your local time zone and depends upon the time in the users' computers being correct.

I could correct for time zone differences, but I can't correct for computer clocks being off without being able to send a corrected time from some server.

Old Pedant
06-19-2012, 09:40 PM
By the by: "Feilding"??? Shouldn't that be "Fielding"? Old Pedant strikes again?

xelawho
06-19-2012, 10:16 PM
otherwise hideously unreliable sources tell me that
Feilding (Maori: Aorangi) is a town in the Manawatu-Wanganui Region of the North Island of New Zealand.

Old Pedant
06-19-2012, 10:39 PM
Ohh...so maybe it really is pronounced "Fail-ding" in which case the spelling is correct.

You like my hack so I didn't have to change his times to 20:15, et al.?

xelawho
06-19-2012, 10:51 PM
considering it's in New Zealand I suspect it would be pronounced something like Fill-Dung (sorry, Mark - Australian blood runs deep)

I do like the time hack, btw. Another one stashed in the bag of tricks :thumbsup:

Old Pedant
06-19-2012, 11:22 PM
So his bus trip is just about the same length trip as we would make to go from our home (near Seattle, Washington) to Spokane, and less than the distance to Pullman. Which is how far football and other fans drive to attend games at the "other school" in this state. (University of Washington is in Seattle, Washington State University is in Pullman. And many fans drive one way or the other for all games.) So I dunno if "long distance" qualifies here. <grin/>

xelawho
06-19-2012, 11:34 PM
definitely relative. for a Kiwi, a trip like that would be like you driving from Phoenix to Seattle.

Old Pedant
06-19-2012, 11:48 PM
Well, shoot, for a kiwi any trip over 2 kilometers would be a long distance. They can't fly and those little short legs of theirs must make any walking at all tough.

Oh, wait... You said Kiwi. Not kiwi. <grin style="silly"/>

Mark Wasley
06-21-2012, 08:54 PM
Hi everyone.

Thanks for the code.

I actually grew up in Feilding. The town was named after Colonel William Henry Adelbert Feilding, a director of the Emigrants and Colonists Aid Corporation Ltd. who negotiated the purchase of a 100,000 acre (400 kmē) block of land from the Wellington provincial government in 1871. The first settlers arrived from Great Britain on 22 January 1874.

The man's name was Feilding

Cheers. Mark.

Mark Wasley
06-21-2012, 08:56 PM
Also, you can checkout the Feilding website for more about Feilding - it has recently been updated.

www.feilding.co.nz (http://www.feilding.co.nz)

Old Pedant
06-22-2012, 02:12 AM
The town was named after Colonel William Henry Adelbert Feilding, a director of the Emigrants and Colonists Aid Corporation Ltd. who negotiated the purchase of a 100,000 acre (400 kmē) block of land from the Wellington provincial government in 1871. The first settlers arrived from Great Britain on 22 January 1874.

The man's name was Feilding


Oh, so he didn't know how to spell his own name, obviously. <grin/>

Or maybe his parents grew up before "i before e except after c" was invented.

Seriously, I took the correction already. Just a very unusual spelling in English, of course.

Now the big question: Did the code make sense to you?

Mark Wasley
06-25-2012, 05:12 AM
Hi Again.

The code is great. I just need to know how to 'set it' to 'go' this Saturday.

Thankyou.

Old Pedant
06-25-2012, 07:22 AM
??? Put it on a web page and it's ready to go.

As I said, it ignores the date, so you can test it tomorrow, if you want.

I'd say just put it on a page with a weird name (e.g., http://www.yoursite.com/zzzzmytrip.html) so nobody is likely to discover it. Then just change the name of the page before you leave the house on Saturday.

HOWEVER...

If you really want to, we could "turn it off" except for the given date, if you really want to.

Mark Wasley
06-25-2012, 08:37 AM
Hi.

I have tested it out. It works fine. I would prefer that only works on the given date of Saturday 30th June (this Saturday).

Mark

Old Pedant
06-25-2012, 07:48 PM
Okay, it was easier to do that than even I thought.

Only lines in red below need to be added.


<!DOCTYPE html>
<html>
<body>
<h1>Mark's Bus Ride</h1>
<br/><br/>
<h3 id="message"></h3>

<script type="text/javascript">
var stations = [
['Palmerston North Central','0.00am','11.30am'],
['Feilding','12.00pm','12.00pm'],
['Hunterville','12.35pm','12.35pm'],
['Taihape','1.10pm','1.45pm'],
['Waiouru','2.10pm','2.10pm'],
['Turangi','2.50pm','2.50pm'],
['Taupo','3.45pm','4.25pm'],
['Tokoroa','5.20pm','5.20pm'],
['Putaruru','5.40pm','5.40pm'],
['Tirau','5.45pm','5.45pm'],
['Cambridge','6.05pm','6.05pm'],
['Hamilton Central','6.30pm','6.30pm'],
['Ngaruawahia','6.50pm','6.50pm'],
['Huntly','7.10pm','7.10pm'],
['Bombay Service Centre','7.40pm','7.40pm'],
['Manakau','7.50pm','7.50pm'],
['Auckland City Central','8.15pm','11.59pm']
];

// this function converts "3.11pm" to minutes since midnight
function getTime( txt )
{
var ampm = txt.substring( txt.length - 2 );
var hm = txt.substring( 0, txt.length - 2 ).split(".");
var hr = Number(hm[0]);
var mn = Number(hm[1]);
if ( ampm.charAt(0) == "p" && hr < 12 ) hr += 12;
return hr * 60 + mn;
}

function where( )
{
var msg = document.getElementById("message");

var now = new Date();

// this will only run on June 30th!
if ( now.getMonth() != 5 || now.getDate() != 30 )
{
msg.innerHTML = "";
return;
}

// current time as minutes since midnight
var curmin = Math.round(
now.getHours() * 60 + now.getMinutes() + ( now.getSeconds() / 60 ) );

// search through stations to see where we are
var lastFrom = 0;
var lastStation = "Home";

for ( var s = 0; s < stations.length; ++s )
{
var stn = stations[s];
var name = stn[0];
var tfrom = getTime( stn[1] );
var tto = getTime( stn[2] );
if ( curmin >= tfrom && curmin <= tto )
{
// we are AT a station
msg.innerHTML =
"Mark is in " + name + " on the Naked Bus.";
return;
}
else if ( curmin > lastFrom && curmin < tfrom )
{
// we are approaching a station
arrive = tfrom - curmin;
msg.innerHTML =
"Mark is between " + lastStation + " and " + name + " on the Naked Bus.<br/>"
+ "Mark will be in " + name + " in " + arrive + " minutes.";
return;
}
lastStation = name;
lastFrom = tfrom;
}
}
where( );
setInterval( where, 15000 ); // recheck every 15 seconds
</script>
</body>
</html>

Don't be put off by the fact that I am looking for month #5. In JavaScript, months are numbered starting from zero, so January==0, February==1, etc.

Mark Wasley
06-25-2012, 09:00 PM
Thankyou. It's all ready to go.

Mark

Mark Wasley
06-26-2012, 08:06 AM
Good Evening NZ TIME.
I have changed up the script a little to look like the below.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Naked Bus Trip Test page </title>
</head>
<body>
<div><font face="Georgia"><strong><img alt="" title="" src="images/bus.png" height="40" width="97" align="left" /></strong></font></div>
<div><font style="font-size: large"><font style="font-size: 14px"><strong>&nbsp;Mark's Naked Bus Trip - </strong><font color="#ff0000">Northbound</font></font><br />
</font></div>
<div>&nbsp;<u></u><u></u><strong>Palmerston North to Auckland</strong></div>
<div><strong><font style="font-size: 18px">&nbsp;<font style="font-size: 16px">Saturday 30th June 2012</font></font></strong></div>
<div><strong><font style="font-size: 18px"><font style="font-size: 16px"><font size="null"></font><br />
</font></font></strong></div>
<p id="message"><font face="Georgia"></font></p>
<script type="text/javascript">


var stations = [
['Palmerston North Central','9.00am','11.30am'],
['Feilding','12.00pm','12.00pm'],
['Hunterville','12.35pm','12.35pm'],
['Taihape','1.10pm','1.45pm'],
['Waiouru','2.10pm','2.10pm'],
['Turangi','2.50pm','2.50pm'],
['Taupo','3.45pm','4.25pm'],
['Tokoroa','5.20pm','5.20pm'],
['Putaruru','5.40pm','5.40pm'],
['Tirau','5.45pm','5.45pm'],
['Cambridge','6.05pm','6.05pm'],
['Hamilton Central','6.30pm','6.30pm'],
['Ngaruawahia','6.50pm','6.50pm'],
['Huntly','7.10pm','7.10pm'],
['the Bombay Service Centre','7.40pm','7.40pm'],
['Manakau','7.50pm','7.50pm'],
['Auckland City Central','8.15pm','9.00pm']
];




// this function converts "3.11pm" to minutes since midnight
function getTime( txt )
{
var ampm = txt.substring( txt.length - 2 );
var hm = txt.substring( 0, txt.length - 2 ).split(".");
var hr = Number(hm[0]);
var mn = Number(hm[1]);
if ( ampm.charAt(0) == "p" && hr < 12 ) hr += 12;
return hr * 60 + mn;
}


function where( )
{
var msg = document.getElementById("message");


var now = new Date();

// this will only run on June 30th!
if ( now.getMonth() != 5 || now.getDate() != 30 )
{
msg.innerHTML = "";
return;
}


// current time as minutes since midnight
var curmin = Math.round(
now.getHours() * 60 + now.getMinutes() + ( now.getSeconds() / 60 ) );




// search through stations to see where I am
var lastFrom = 0;
var lastStation = "Home";


for ( var s = 0; s < stations.length; ++s )
{
var stn = stations[s];
var name = stn[0];
var tfrom = getTime( stn[1] );
var tto = getTime( stn[2] );
if ( curmin >= tfrom && curmin <= tto )
{




// I am AT a station
msg.innerHTML =
"Mark is at <b> " + name + " </b> on the Naked Bus.";
return;
}
else if ( curmin > lastFrom && curmin < tfrom )
{




// I am approaching a station
arrive = tfrom - curmin;
msg.innerHTML =
"Mark is between <b> " + lastStation + " </b> and <b> " + name + " </b> on the Naked Bus.<br/>"
+ "He will be at <b> " + name + " </b> in <b> " + arrive + " </b> minutes.";
return;
}


lastStation = name;
lastFrom = tfrom;


}
}




where( );
setInterval( where, 5000 ); // recheck every 5 seconds


</script>
</body>
</html>



I have put bold tags around the towns/cities & the number of minutes to take to get to the next town/city.

What I want to do ... but I need help with is


1) Make the script which I posted above (You can find at http://mark-wasley.exofire.net/NakedBusTrip.php) look like the script on the home page (http://mark-wasley.exofire.net/)
To view script (on NakedBusTrip.php page - Right click, View source - It has the bit to only go on Saturday inserted
The script on the home page doesn't have the Saturday bit inserted as I want to be able to see that work on the NakedBusTrip.php page (with all the fonts & formatting) before I put the Saturday bit in.

2) Summarise details about the trip that is happening "right now"
I would like this in JavaScript & to look a little like the Hello Bar (http://hellobar.com)
I don't know how to do it & would like the following brief details:

* My bus image (can be found on any of my listed website links)
* The text: Mark's Naked Bus Trip - Northbound
* My current town/city (e.g. Current Location: Feilding)
or * Where I will be next (e.g Next Location: Hunterville, in X minutes)
* Black Background. Text in White. with the location in BOLD & number of minutes also in BOLD

3) Instead of 'station' & 'stations' being used I would like the terms 'stop' *& stops'. In New Zealand we call 'bus stations' as 'bus stops'

I would appreciate this sorted out.


Thankyou!!! Mark.

Philip M
06-26-2012, 08:45 AM
Mark - you are asking a lot of Old Pedant who has been extremely generous with his time and expertise already. Bearing in mind that this page applies only to just one day, and will presumably be seen by only a very limited number of people, I think you should not keep taking your pitcher to the well.

You should be capable of making some of these changes (such as bus station/bus stop) yourself. Likewise you should be able to style the message.

But naturally if Old Pedant can find the time to do as you ask then that is entirely up to him.

Mark Wasley
06-27-2012, 09:05 PM
Hi there.


Firstly, I am very grateful for all the help given.


Secondly, I have managed to now change the script/code to use 'stop' & 'stops' instead of 'station' & 'stations', after having problems previously.


Thirdly, I have also managed to style the message.

Lastly, I would appreciate any help with the header bar that basically does the same thing as The Hello Bar (http://www.hellobar.com).


Thankyou & Regards,
Mark

Old Pedant
06-28-2012, 12:23 AM
3) Instead of 'station' & 'stations' being used I would like the terms 'stop' *& stops'. In New Zealand we call 'bus stations' as 'bus stops'

WHY IN THE WORLD would this EVER matter???? You could have called them "flurp" and "flurps" for all anybody looking at the page would ever care. Those words don't APPEAR anywhere on the page. They are just arbitrary names in the JavaScript code. Heck, you could call them "PrinceWilliam" and "PrinceAndrew" and the code would all work identically. Who cares about JavaScript variable names?????

Old Pedant
06-28-2012, 12:26 AM
As for the "HELLO"-looking top line: That is 100% a matter of changing the HTML and CSS. It really has NOTHING to do with the JavaScript. (Small exception: The JS code is putting a <br/> in the text when you are between Princes [stations, stops, whaddever] that presumably you would replace with just a space.

Here's a simple-minded demo:


<!DOCTYPE html>
<html>
<body style="margin: 0 0 0 0;">
<div style="text-align: center; vertical-align: middle; color: white; background-color:black; padding:5px;">
<span id="message" style="font-family: arial; font-size: 16px;"></span>
&nbsp;
<img src="http://mark-wasley.exofire.net/images/buslookingright.png" height="30" />
</div>

<h1>Mark's Bus Ride</h1>
<br/><br/>
<br/><br/>
<br/><br/>
<br/><br/>
<br/><br/>
<script type="text/javascript">
var stations = [
['Palmerston North Central','0.00am','11.30am'],
['Feilding','12.00pm','12.00pm'],
['Hunterville','12.35pm','12.35pm'],
['Taihape','1.10pm','1.45pm'],
['Waiouru','2.10pm','2.10pm'],
['Turangi','2.50pm','2.50pm'],
['Taupo','3.45pm','4.25pm'],
['Tokoroa','5.20pm','5.20pm'],
['Putaruru','5.40pm','5.40pm'],
['Tirau','5.45pm','5.45pm'],
['Cambridge','6.05pm','6.05pm'],
['Hamilton Central','6.30pm','6.30pm'],
['Ngaruawahia','6.50pm','6.50pm'],
['Huntly','7.10pm','7.10pm'],
['Bombay Service Centre','7.40pm','7.40pm'],
['Manakau','7.50pm','7.50pm'],
['Auckland City Central','8.15pm','11.59pm']
];

// this function converts "3.11pm" to minutes since midnight
function getTime( txt )
{
var ampm = txt.substring( txt.length - 2 );
var hm = txt.substring( 0, txt.length - 2 ).split(".");
var hr = Number(hm[0]);
var mn = Number(hm[1]);
if ( ampm.charAt(0) == "p" && hr < 12 ) hr += 12;
return hr * 60 + mn;
}

function where( )
{
var msg = document.getElementById("message");

var now = new Date();
// current time as minutes since midnight
var curmin = Math.round(
now.getHours() * 60 + now.getMinutes() + ( now.getSeconds() / 60 ) );

// if ( test != null ) curmin = test;

// search through stations to see where we are
var lastFrom = 0;
var lastStation = "Home";

for ( var s = 0; s < stations.length; ++s )
{
var stn = stations[s];
var name = stn[0];
var tfrom = getTime( stn[1] );
var tto = getTime( stn[2] );
if ( curmin >= tfrom && curmin <= tto )
{
// we are AT a station
msg.innerHTML =
"Mark is in <b>" + name + "</b> on the Naked Bus.";
return;
}
else if ( curmin > lastFrom && curmin < tfrom )
{
// we are approaching a station
arrive = tfrom - curmin;
msg.innerHTML =
"Mark is between " + lastStation + " and " + name + " on the Naked Bus.&nbsp;&nbsp;"
+ "Mark will be in <b>" + name + "</b> in <b>" + arrive + "</b> minutes.";
return;
}
lastStation = name;
lastFrom = tfrom;
}
}
where( );
setInterval( where, 15000 ); // recheck every 15 seconds
</script>
</body>
</html>


That doesn't have the Saturday only code in it. You can add it back in.

Mark Wasley
06-29-2012, 11:21 PM
Hi all.

Today is the day

I've decided to ditch the Header Bar idea... too complicated.

If you want to see my finished product check out www.marksbustrip.tk (http://marksbustrip.tk)

Regards,
Mark.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum