API that determines the time zone based on geo location (coordinates or region or country). Using "geotimezone_query($location, $format);" that returns time zone identifier or UTC/GMT offset or both (depends on $format value). Where the first parameter is an associative array with array keys of:

longitude
latitude
regionCode
region
countryCode

To determine the time zone based on coordinates, the 'longitude' and 'latitude' keys are required to have valid coordinates values. E.g.

geotimezone_query([
  'latitude'  => '14.5995',
  'longitude' => '120.9842',
]);

... will return:

Array
(
  [identifier] => Asia/Manila
  [offset] => +08:00
)

To determine the time zone based on region, the 'countryCode' and either of 'regionCode' or 'region' are required. E.g.

geotimezone_query([
  'region'      => 'Quezon City',
  'countryCode' => 'PH',
]);

... will return:

Array
(
  [identifier] => Asia/Manila
  [offset] => +08:00
)

To determine the time zone based on country, the 'countryCode' is required. E.g.

geotimezone_query([
  'countryCode' => 'AU',
]);

... will return:

Array
(
  [identifier] => Array
    (
      [0] => Australia/Darwin
      [1] => Australia/Lindeman
      [2] => Australia/Brisbane
      [3] => Australia/Lord_Howe
      [4] => Australia/Eucla
      [5] => Australia/Perth
      [6] => Australia/Broken_Hill
      [7] => Australia/Sydney
      [8] => Australia/Adelaide
      [9] => Australia/Melbourne
      [10] => Australia/Currie
      [11] => Australia/Hobart
    )
  [offset] => Array
    (
      [0] => +09:30
      [1] => +10:00
      [2] => +10:00
      [3] => +10:30
      [4] => +08:45
      [5] => +08:00
      [6] => +09:30
      [7] => +10:00
      [8] => +09:30
      [9] => +10:00
      [10] => +10:00
      [11] => +10:00
    )
)

If all keys are present, the coordinates (longitude/latitude) are the query's priority (the rest will be ignored). The region is the next query's priority if coordinates are not present. And the country is the last priority if coordinates and region are not present.
It is recommended to provide coordinates for accurate time zone while region is the next accurate and the least is the country where it may return multiple time zones in array.

This module does not need web services, data files or SQL database. This is a Drupal version of LatLongToTimezone project (https://github.com/drtimcooper/LatLongToTimezone).

Project information

Releases