0

In a PHP script/web application, I need to take any historical time and date and convert it into GMT or UTC. I would know the latitude and longitude co-ordinates associated with each time and date, so perhaps I could derive the time zones from that somehow.

I'm vaguely aware of the Olson or 'tz' database but I'm not sure how far that is available for programmatic interrogation, or how far its incorporation into PHP5 can answer my task.

As I understand it, this tz database is only really accurate for data after 1970, and that it makes approximations for earlier dates. If methods are likely to be error-prone for times before 1970 then perhaps at least I can flag such a case as a dubious result.

nev
  • 133
  • 3
  • 10
  • Unless you're referring to historical times (centuries) then _ *as far as I'm aware* _ there's no reason that knowing a location (lat/long) would not give a correct time for that location, in say the last 200 years. For other times there's various issues with different calendars..... – Martin Feb 18 '18 at 17:01
  • [This answer may interest you](https://stackoverflow.com/a/16070531/3536236) – Martin Feb 18 '18 at 17:02
  • How historical are we talking? – Evert Feb 18 '18 at 17:04
  • And how accurate do you need to be? – Martin Feb 18 '18 at 17:04
  • By 'historical" I'm saying back about 100 years. Not sure what to say about the accuracy, except as precise as I can get it I guess. – nev Feb 18 '18 at 17:12
  • Can you explain a little more with examples what you're actually looking for and what data you actually have to work with? (edit and update your question don't add details to comments)Thanks. – Martin Feb 18 '18 at 17:27
  • I think what I need is a service like [Google's API] (https://developers.google.com/maps/documentation/timezone/start) to derive the timezone from lat/long co-ordinates. However this API explicitly [states] (https://developers.google.com/maps/documentation/timezone/intro) that it "does not take historical time zones into account". The times/dates I would be working with (i.e., those seen on clocks at the location) _would_ be historical, as far back as about 100 years. So maybe there is no API that can do this. – nev Feb 18 '18 at 18:57
  • 1
    You need to define your requirements more accurately. When you say "back about 100 years", that's not very clear. Also, understand that the tz database is *the* most accurate database of time zones that exists. It has many values before 1970 also, but it cannot guarantee that for the whole world because time zones as we use them today were not invented then! – Matt Johnson-Pint Feb 18 '18 at 22:26
  • My web app gets times & dates of events (eg 09:15, 4 July 1960) & the latitude and longitude of the event. The dates will go back up to 100 years from the present. I would like to ascertain the time zone of the event. I'm using Google Maps Time Zone API, but I understand this may not be as accurate as Olson for historical dates. I do not know how to query Olson. – nev Feb 19 '18 at 11:30
  • Ideally, as my question title implied, I would like to convert the historical time & date to UTC/GMT (the time and/or date may or may not be different). I thought getting the time zone for the historical date might be the first step in doing this. – nev Feb 19 '18 at 11:48
  • I don't have a suggestion on solving the problem beyond what is above, but once you do, I suggest calling the result UT, for Universal Time. That is a generic term for UTC, GMT (as understood today), and similar timescales when the finer distinctions are not important. UTC didn't exist before 1960 and before 1925 GMT, in maritime circles, GMT could start the day at noon rather than midnight. – Gerard Ashton Feb 19 '18 at 12:06

1 Answers1

0

First, use one of the methods listed here to get the TZ Database identifier for the lat/lon provided.

Then, if the date is covered by the TZDB, you can just use the built-in PHP methods for conversion. If those fail, then the you have two options:

  • You can use the Local Mean Time (LMT) value for that time zone from the TZDB, for entries that have them.

  • You can calculate the local solar time for the exact position, using the longitude.

Either option will be making grand assumptions about how local time was actually kept in that location at the given time.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
  • Using the Google Maps Time Zone API, the PHP methods seem necessary, since the former returns a raw offset from UTC and a DST offset value. I'm just not sure if I can trust it for older dates. – nev Feb 21 '18 at 17:13
  • You can only trust it as far as the TZDB data goes back. Google doesn't have any different or more complete information than that. It's important to recognize that time zones as we understand them today are a relatively modern invention. – Matt Johnson-Pint Feb 21 '18 at 17:53
  • Understood. (I meant "seem unnecessary" btw) – nev Feb 21 '18 at 20:38