View Full Version : Ferry Timetable Script, "Ferry Leaves in ? mins"

Waldo Pepper
02-23-2011, 12:26 AM

I'm not sure whether this would be better as PHP or Javascript, so thought i'd try here first.

Basically what I want is to display on a line in my website that "The next ferry leaves in XX mins". The website page is in PHP.

I have a ferry timetable, which leaves at varying intervals throughout the day. There are 2 timetables, one for Monday to Friday, the other for Saturday/Sunday.

Is this achievable?

I've seen it done in iPhone apps, in fact I have an app on my iPhone for this very ferry schedule.

I know a little bit of both PHP & Javascript, but only enough to get me into trouble and to think that it could be done in either of these.

Thanks for your help,

02-23-2011, 01:48 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<script type="text/javascript">
var Departures=[

function Departure(id,ary,os){
var today=new Date().getTime();
today=new Date(today+os);
var year=today.getFullYear();
var month=today.getMonth();
var date=today.getDate();
var ary=ary[today.getDay()];
var hm,d;
for (var z0=0;z0<ary.length;z0++){
d=new Date(year,month,date,hm[0],hm[1]);
if (d>today){
var minutes=parseInt((d-today)/1000/60);
var hours=parseInt(minutes/60);
setTimeout(function(){ Departure(id,ary,os); },60*1000);

var SeverDate='2011:1:23:14:34'; // the ferry port date and time - PHP used to produce this date

var sms=SeverDate.split(/\D/);
sms=new Date(sms[0],sms[1],sms[2],sms[3],sms[4]).getTime();
var ms=new Date().getTime();


<body onload="Departure('tst',Departures,sms-ms);">
<span id="tst" ></span>