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

php, timezone

Solution

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

Problem

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?

Original source

Related problems