A time and place for everyone

This is for software gurus with a love for geo-data who want to help us make Twisst run smoother.

To send people correct ISS-alerts, we need to know in which timezone they are. We need a script to tell us that.

The problem

To find out their timezone, we send peoples coordinates to the Geonames server. Geonames is an awesome service. However, sometimes Geonames is swamped with requests and then we don't get timezones. New followers then are left with UTC as their default timezone, which leads to confusion.

Also, sending requests to Geonames all the time causes a lot of data traffic. We would like to cut on our diet of data traffic.

The solution

So, we would like to figure out ourselves which timezone to use for certain coordinates. From what we gather, this is not impossible. It takes a map with the timezones of the world as polygons and a script to find out in which polygon a set of coordinates lies.

This is what a solution for Twisst would look like:

  • accurate for many different places in the world (we currently have followers from 163 countries in the world)
  • not too cpu-intense
  • simple to integrate into our system: put lat/long in a function, get Olson strings like 'Europe/Berlin' back.
  • needs to run on LAMP (Mysql 5.1, PHP 5.2)


Below are a few links to sources we found. We hope you will want to give it a try and help us out with a bit of cool software.



Point-in-polygon in PHP


Post links to your code (on pastebin.com for instance) in the comments.



@ Jonathan thank you for your reply!

What we are doing on our server, is leaving the handling of daylight saving time to PHP. Once we have the Olson string, PHP is very good at converting timezones while taking DST into account.

Just a bold question: is there any chance you would licence your solution to us? You can contact me through e-mail address jaap @ thisdomain.

@ Tony Yes it does, but the problem is that most people leave that timezone setting at its default. We can't rely on it for the working of our mashup and therefore have to infer timezone from the location.


Doesn't the twitter API already show the user's UTC offset in an integer format (in seconds I think) and a text version of the Time Zone.


I did this problem a while ago for my EarthTools website. I made the interface available through a very simple web service: http://www.earthtools.org/webservices.htm#timezone

I essentially did the same thing but rather than worry about determining whether a particular point is inside a polygon (which seems inefficient for a highly-queried service), I essentially mapped the time zone map to an image and then it's essentially just a case of querying a point in a 2D table.

Worrying about daylight saving time is the challenge - the rules for DST are very fluid but can be determined from the Olson tz data. I don't know of any way to determine a map of daylight saving time areas - the regions that do and do not have DST are not aligned with the time zone regions themselves (i.e. part of one time zone may have DST while another part of the same time zone may not).


Interesting, but then how do I find out in which polygon a set of coordinates lie?


To get a hold of the data in human-readable form, get tz_world.zip from efele.net, then
aptitude install gdal-bin
ogr2ogr -f 'GeoJSON' tz_world.json tz_world.shp

This will give you a text file 'tz_world.json' in JSON format.

Syndicate content