Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get timezone from airport code (IATA/FAA)

Tags:

timezone

php

I am trying to make a PHP function that returns the UTC timezone for a given airport code (IATA/FAA).

What the function should do is something like this:

echo getTimezoneFromAirportCode("CPH"); // +1
echo getTimezoneFromAirportCode("CXI"); // +14

To make this function I need a list of all aiport codes and their timezones.

By searching a bit I found this list: https://sourceforge.net/p/openflights/code/HEAD/tree/openflights/data/airports.dat?format=raw (Source: http://openflights.org/data.html)

After looking up a couple of airport codes in the list I found out that some of the data was incorrect. For instance it lists CXI to be in the UTC -12 timezone - which according to this page is incorrect.

Does any of you know a public list that provides the data needed to make the getTimezoneFromAirportCode function?

like image 960
Casper André Casse Avatar asked Dec 12 '13 20:12

Casper André Casse


People also ask

How do you read an airport code?

Those codes are actually four letters long: The first letter describes the country, and the remaining three letters mark the specific airport. For instance, Florida's Fort Lauderdale-Hollywood International Airport would be KFLL; the “K” is for U.S. and “FLL” is the specific airport code.

Can airports have the same IATA code?

"After an airline is delisted, IATA can make the code available for reuse after six months and can issue "controlled duplicates". Controlled duplicates are issued to regional airlines whose destinations are not likely to overlap, so that the same code is shared by two airlines.

What airport code is IATA?

The International Air Transport Association's (IATA) Location Identifier is a unique 3-letter code (also commonly known as IATA code) used in aviation and also in logistics to identify an airport. For example, JFK is the IATA code for, you might know it, New York's John F.

Will IATA codes run out?

Codes can be reassigned over time. According to the Wikipedia article on IATA codes there have been several IATA codes that have been reassigned. IATA has a mechanism for assigning these airport codes that's available online.


2 Answers

I've managed to find a solution to the issue. Through the flightstats.com API it is possible to get a free but limited access to a complete airport database: https://developer.flightstats.com/api-docs/airports/v1

The API returns all active/inactive airports in the following format:

{
   "fs": "LAX",
   "iata": "LAX",
   "icao": "KLAX",
   "faa": "LAX",
   "name": "Los Angeles International Airport",
   "street1": "One World Way",
   "street2": "",
   "city": "Los Angeles",
   "cityCode": "LAX",
   "stateCode": "CA",
   "postalCode": "90045-5803",
   "countryCode": "US",
   "countryName": "United States",
   "regionName": "North America",
   "timeZoneRegionName": "America/Los_Angeles",
   "weatherZone": "CAZ041",
   "localTime": "2014-06-20T06:00:50.439",
   "utcOffsetHours": -7,
   "latitude": 33.943399,
   "longitude": -118.408279,
   "elevationFeet": 126,
   "classification": 1,
   "active": true,
   "delayIndexUrl": "https://api.flightstats.com/flex/delayindex/rest/v1/json/airports/LAX?codeType=fs",
   "weatherUrl": "https://api.flightstats.com/flex/weather/rest/v1/json/all/LAX?codeType=fs"
}

This was exactly the data I needed to be able to make my function:

echo getTimezoneFromAirportCode("LAX"); // -7

The data is available through the following GET request:

https://api.flightstats.com/flex/airports/rest/v1/json/all?appId=[appId]&appKey=[appKey]

[appId] and [appKey] will be provided after creating a free flightstats.com developer account here: https://developer.flightstats.com/signup

like image 57
Casper André Casse Avatar answered Oct 11 '22 10:10

Casper André Casse


You are confusing a "time zone" with a "time zone offset". They are not the same thing. You can't just ask for the offset at a location - you also would need to know the specific time in question. It's invalid to ask "What's the time zone offset for LAX" - because in the winter it will be -8 while in the summer it will be -7.

You can ask "what is the offset at this location right now", but that might give you a different answer depending on when you ask. So the date and time have to be part of the input.

What you really need to know instead is that LAX corresponds to the IANA time zone of America/Los_Angeles. These time zone codes are understood by the PHP date/time API, and many other systems. (.NET Windows users can convert these to Microsoft Windows time zones using my TimeZoneConverter library.)

To do this, you need to take the latitude and longitude of each airport (which are available from OpenFlights and many other places), and use one of the methods described here to lookup the IANA time zone for those coordinates.

I've already written code for this in C#, which you can find here. The output is included in a .csv file, which you can parse and use in any language you like. It includes both IANA and Microsoft time zones.

Be sure to also read the timezone tag wiki, especially the parts on the IANA database, and the section titled "Time Zone != Offset".

Also note that while the lat/lon coordinates in the OpenFlights database are great, the time zone data in that file is not very accurate, so going through the process I described is important. When it comes to the specifics of time zones, you should only trust the IANA database and make sure you keep updated.

like image 25
Matt Johnson-Pint Avatar answered Oct 11 '22 09:10

Matt Johnson-Pint