2

I am writing PHP app that uses timezones. For land based GPS, I use

date_default_timezone_set();

with correct name like Europe/Dublin. However, if the GPS location is not land but it is on the sea, there is no timezone name, but time is offseted from UTC. The calculation is aprox. 1 hour for 15 degrees of longitude. I have calculated UTC offset manually, but I am not able to set it to PHP. I am using date method to print human-readable dates from unix timestamps.

I have found that there are Others timezones names (https://www.php.net/manual/en/timezones.others.php) like Etc/GMT+10, but the PHP documentation states this:

Warning Please do not use any of the timezones listed here (besides UTC), they only exist for backward compatible reasons, and may expose erroneous behavior.

Is it safe to use the Etc-based offsets? Or is there any other safe solution? I have not found any. In date_default_timezone_set() comments someone "uses" this: https://www.php.net/manual/en/function.date-default-timezone-set.php#96551 but it seems very ugly.

I am using PHP 7.1.

Martin Perry
  • 9,232
  • 8
  • 46
  • 114

1 Answers1

1

The time zones in PHP originate from the IANA tz database.

In particular, zones like Etc/GMT+10 originate from the etcetera file in the tz data, which says (emphasis mine):

... These days, the tz files cover almost all the inhabited world, and the only practical need now for the entries that are not on UTC are for ships at sea that cannot use POSIX TZ settings.

Thus, you can indeed and should use them for the purpose you described.

Keep in mind that they only exist for whole-hour offsets from Etc/GMT-14 to Etc/GMT+12, and that the sign in the zone name is opposite from standard conventions. In other words Etc/GMT+10 is actually UTC-10.

One other note. My understanding is that it is common for ships at sea to use a land-based time zone when they are in the territorial waters near such lands, including any daylight saving time adjustment in effect. For example, a ship traveling within the territorial waters of the USA along the Pacific coast should change their clocks to use PST (UTC-8) in the winter and PDT (UTC-7) in the summer. This is modeled by America/Los_Angeles, whereas a pure longitudinal calculation would use UTC-8 year-round (Etc/GMT+8).

All of this is flexible, as the captain of the ship can basically decide the shipboard time at their discretion. See Wikipedia's article on nautical time for more specifics.

You might also want to read here about methods to use GPS coordinates to resolve an IANA time zone. Those that use the Time Zone Boundary Builder project as a data source (such as the Geo-Timezone PHP library) benefit from both nautical time and territorial waters being taken into consideration.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575