Mapping zip codes to time zone - preferably with info about daylight savings

This isn’t specifically a PHP question but since that’s what our app is using, I thought I’d start here. The application we’re developing requires time stamps on certain things and they need to be based on the user’s actual time. Obviously we can collect time zone info when they register but are there some behind the scenes way to get the information from the zip code they give us? Preferably something free.


PECL Extension: GEOIP

http://php.net/manual/en/function.geoip-time-zone-by-country-and-region.php

Were it me, i’d use a database (GeoNames puts out a TSV file for the US: http://www.geonames.org/export/zip/US.zip ) to translate Zip to State, and then map State to time zone ([FPHP]geoip_time_zone_by_country_and_region[/FPHP])

Thanks for the tips.

Could you possibly determine their time zone at the time of registration or some other time when the user is on the site via javascript? With this technique, you could look at their local time on their machine and use that to determine their time zone and post that data back to your server.

This project allows you to determine the time zone via javascript:
https://bitbucket.org/pellepim/jstimezonedetect

Wouldn’t this have to assume that the user has their clock set correctly?

and that the user was allowing Javascript…
and that the user never went on a business trip or vacation…

The Javascript isn’t an issue because it’s a fairly complex online app that they have to have a subscription to. One of the requirements for the app to work is that they allow Javascript. However, your observation about business trips or vacations is a good one because theoretically, a user MIGHT take their laptop on a business trip and want to get caught up on their record-keeping.

This is why you use geoIp to get their starting location (if you want) but allow them to enter their own zip if they see that it is incorrect, you can still use geoIp to obtain info based on that rather than IP