0

Im trying to calculate flying time of a journey using PHP.

Scenario:

Deprature from Chennai 12:00 hrs
Arrival at Singapore   18:30 hrs

The timezone difference between chennai and singapore is 2H:30M so the flying time is 4H from the above scenario.

I use moment.js and I simply cant subtract ArrivalTime - DepartureTime because the TimeZone must also be considered.

I have got only the Airport Code as a key to find the time zone but in PHP I cant use Airport Code for timezone. What is the best way to calculate the flying time of a flight?

Ashik Basheer
  • 1,531
  • 3
  • 16
  • 36
  • 1
    try a couple of things by yourself, first, before asking others to work it out for you – Elias Van Ootegem Jul 27 '14 at 09:50
  • Convert both times to GMT, then to epoch, then subtract. – Nicholas Hamilton Jul 27 '14 at 10:10
  • Is this the *only* case you need to handle? If so, you're in luck that both locations have fixed-offset time zones. Chennai is always UTC+05:30 and Singapore is always UTC+08:00. But I think you are looking for an answer that resolves the general case of using any airport - so you would need to resolve to a real time zone so you can handle locations where the offset changes for daylight saving time. – Matt Johnson-Pint Jul 27 '14 at 18:00
  • This is just one example. There are more than 50 cities! – Ashik Basheer Aug 01 '14 at 19:03

2 Answers2

2

I think you will have to create an array associating the airport code to the corresponding timezone. Couldn't find a ready one ... sry

There seems to be an API for this, check out this post: How to get timezone from airport code (IATA/FAA)

Community
  • 1
  • 1
minychillo
  • 395
  • 4
  • 17
2

Geonames data contains airport codes and names with their time zone. You will need to extract the airports from the other data (it includes towns, cities and various other landmarks) then store the airport code to time zone map in a database or just a big associative array. This isn't a ready made solution but it's a good place to start.

http://download.geonames.org/export/dump/

You can then use the timezones of the origin and destination airports to work out the time difference.

Dave Morrissey
  • 4,371
  • 1
  • 23
  • 31