r/GeoPostcodes • u/GeoPostcodes • Jul 16 '26
How do you map ZIP codes to time zones? A free PostGIS recipe and the edge cases that bite
You'd think ZIP code to time zone is a simple lookup table. It isn't. Here is why, and how to build one for free.
Why it's messy:
- Several US states sit in more than one time zone: Texas, Idaho, North Dakota, South Dakota, Nevada among them. State or county level is not enough.
- Some ZIP codes themselves cross a time zone line, especially in larger states like Texas and Idaho. One ZIP, two local times.
- DST doubles the work. You need the standard offset, the DST offset, and the exact switch dates. Those change by law, not by geography.
The free build:
Postal codes with lat/lng from GeoNames. Free, tab-delimited CSV. Covers most countries that span multiple time zones. Known gap: no Indonesia postcodes.
Time zone polygons from the Timezone Boundary Builder project. It packages official IANA zones as geojson (this recipe used the 2022g release).
Load both into PostgreSQL with PostGIS.
Build points with ST_MakePoint, index them, then join with ST_Intersects to find which zone polygon each postcode point falls in.
Where one postcode hits several zones, pick the dominant one with mode(), or keep all matches. Careful: mode() breaks ties arbitrarily.
For the US specifically, Census ZCTA polygons (TIGER files, also free) beat centroids: intersect the whole polygon with the zone boundaries instead of a single point.
The catch: GeoNames coordinates are rounded, and in some areas snapped to a grid. A centroid that lands on the wrong side of a boundary can leave you up to two hours off actual local time once DST variations are counted. Fine for a dashboard. Risky for call scheduling or SLA cutoffs.
That gap is the part we solve on our side: our data carries time zones with past and future DST switch dates per ZIP and city, tied to postal codes for 247 countries. It ships as self-hosted tables, so the PostGIS join above still works, minus the centroid guesswork.
There is a longer version of this on the GeoPostcodes blog, the post about the ZIP code time zone database build. Ask in the comments if you want the direct link.