Results 1 to 2 of 2

Thread: Ferry Timetable Script, "Ferry Leaves in ? mins"

  1. #1
    Join Date
    Oct 2006
    Location
    Hong Kong
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Ferry Timetable Script, "Ferry Leaves in ? mins"

    Hi,

    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,
    WP

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <!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" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script type="text/javascript">
    /*<![CDATA[*/
    var Departures=[
     ['10:30','11:30','12:10','14:30','15:30','16:30','17:30','18:30','19:30','20:30'],
     ['10:30','11:30','12:10','14:30','15:30','16:30','17:30','18:30','19:30','20:30'],
     ['10:30','11:30','12:10','14:30','15:30','16:30','17:30','18:30','19:30','20:30'],
     ['10:30','11:30','12:10','14:30','15:30','16:30','17:30','18:30','19:30','20:30'],
     ['10:30','11:30','12:10','14:30','15:30','16:30','17:30','18:30','19:30','20:30'],
     ['10:30','12:10','14:30'],
     ['10:30','12:10','14:30']
    ]
    
    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++){
      hm=ary[z0].split(/\D/);
      d=new Date(year,month,date,hm[0],hm[1]);
      if (d>today){
       date=d;
       var minutes=parseInt((d-today)/1000/60);
       var hours=parseInt(minutes/60);
       minutes-=60*hours;
       document.getElementById(id).innerHTML=((hours<10?'0':'')+hours)+':'+((minutes<10?'0':'')+minutes);
       break;
      }
     }
     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();
    
    
    /*]]>*/
    </script>
    </head>
    
    <body onload="Departure('tst',Departures,sms-ms);">
    <span id="tst" ></span>
    </body>
    
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •