APIs
Time zone API
A time zone API takes a latitude and longitude and returns the IANA zone the point falls in — America/Mexico_City, Europe/Lisbon — together with that zone’s offset from UTC at a moment you choose. oslew returns the zone name, the total offset, and the standard and daylight-saving parts it is made of, for any past or future timestamp. It belongs to the Address product, but its answers come from ODbL-licensed boundaries: you may store them, and a database of them that you share carries share-alike.
Last reviewed
Time zones look like a lookup table and behave like history. A zone’s boundaries move rarely, but the rules inside it change: clocks go forward and back, governments abolish or reintroduce daylight saving, and an offset that was right last year can be wrong this year. A useful time zone API therefore answers two separate questions — which zone holds this point, and what that zone’s offset was, is or will be at a particular instant — and keeps them apart. GET /v1/timezone does exactly that.
What one lookup returns
Send at, a coordinate with latitude first, and optionally timestamp, a unix time in seconds, which may be in the past or the future and defaults to now. The answer:
| Field | Meaning |
|---|---|
tzid |
The IANA zone identifier, such as America/Mexico_City. The thing to store. |
utc_offset_s |
Seconds to add to UTC to get local time at that instant: the standard offset plus any daylight-saving shift. Negative west of Greenwich. |
raw_offset_s |
The zone’s standard offset, ignoring daylight saving. |
dst_offset_s |
The daylight-saving shift in force at the instant, or zero. |
abbreviation |
The abbreviation in force, such as CST or PDT. For display only. |
via |
Whether the point sat wholly inside a zone polygon or near an edge, where the polygon itself decided. |
timestamp, at |
The instant and point the answer is for, echoed back. |
provenance |
The boundary data’s source, release and licence code. |
utc_offset_s is the number to do arithmetic with; the other two offsets explain it. A zone six hours behind UTC with no daylight saving in force returns the same figure in the total and the standard offset and zero for the shift. A zone that observes summer time returns its winter offset as the standard part and an hour as the shift, and the total moves accordingly.
Store the zone, not the offset
The most common time-zone bug is storing an offset against a location. It is right the day it is written and silently wrong from the next clock change onwards. It is also wrong for any other date you later compute with it — an appointment next month, a delivery slot across a daylight-saving boundary, a log line from last year.
Store the tzid instead. It stays true of the place, and every language runtime can turn it into an offset for any instant from its own copy of the tz database. The rules do change: Mexico abolished daylight saving in most of the country in 2022, so the same point in Mexico City had a different September offset before and after. The tz database records that history, and an offset computed for a past instant uses the rules in force then.
Asking about the right moment
The default instant is now, which is right for exactly one question: what time is it there? For anything tied to an event — a meeting, a shipment window, the timestamp on a record — send that event’s time, so the answer reflects the rules in force on the day.
For many instants at one place, do not make a request per instant. Ask once for the zone name, then let your runtime’s tz support compute offsets for each instant. The one caution is currency: a runtime’s tz database can be older or newer than the service’s, and for a zone whose rules changed recently it is worth checking that the two agree.
Where there is no zone
Zone polygons cover land and territorial waters. A point outside all of them — the open ocean — returns a success response with the zone, every offset, the abbreviation and the provenance all empty, rather than a nominal offset the data does not hold. The same happens on a deployment with no time-zone layer loaded. Branch on tzid being empty, not on an error. In the rare case where the polygons name a zone that the compiled tz database does not know, the request is refused with a 400 naming the zone, rather than answered with an invented offset.
Licence: ODbL, although it is on the Address product
This is the detail that catches legal reviews out. The time zone route belongs to the Address product, next to geocoding, but it does not share geocoding’s permissive licence. Zone boundaries come from timezone-boundary-builder, which is derived from OpenStreetMap and published under ODbL-1.0. The offsets come from the tz database compiled into the service.
What that means in practice:
- Storing the answers is allowed. Keeping a zone per customer location, per store or per device in your own systems is use of the data.
- Share-alike applies to a derived database you make public. If you publish a table of zones per location, it is offered under the same licence, with attribution to the source.
- Decide by the code on the answer, not by the product. Every response carries its licence in
provenance, and the licensing page sets out what each code asks of you.
For how this compares with keeping geocoding results from other providers, see can you store geocoding results?.
The zone elsewhere in oslew
A reverse geocode lists the zone in its administrative chain as an entry whose name is the IANA identifier, with no offsets — enough to store, not enough to convert a time. The same zone layer decides opening hours in nearby places search: an open_at instant is turned into a local weekday and minute using the zone at the point you asked about, and the request is refused where no zone holds the point.
What it costs
The time zone route takes one token from the key’s address bucket per request, like a geocode, and runs on every plan. Free allows 1 requests a second sustained, burst 5; the Address plan is $99 a month for 20 requests a second sustained, burst 100, with no monthly quota. There is no batch form, so a backfill of many points is paced to the key’s rate — and because you store the zone rather than the offset, a backfill is a one-time job per location rather than a recurring one.
Limits worth knowing
- Offsets are true of one instant. Reuse the
tzid, not the offset. - Answers are ODbL, like the administrative divisions and unlike the address and place layers beside them.
- No zone over open ocean, and no zone where the layer is not loaded: both return empty fields rather than a guess.
- Coordinates are latitude first; a longitude-first pair from GeoJSON lands somewhere else.
Bottom line
Use the time zone API to attach an IANA zone to every location you hold, and to convert specific instants to local time. Store the zone name, compute offsets per instant, and treat the answers as ODbL data — free to keep and use, with share-alike only if you publish a database built from them.
Questions
How do I get the time zone from a latitude and longitude?
Send the coordinate, latitude first, as the at parameter of GET /v1/timezone, and optionally a unix timestamp. The answer names the IANA zone containing the point and gives its offset from UTC at that instant, split into the standard offset and any daylight-saving shift. Without a timestamp the offsets are for the moment of the request.
Should I store the UTC offset or the time zone name?
The zone name. A point’s zone rarely changes, but its offset changes twice a year where clocks move, and whenever a government changes the rules. Store the IANA identifier per location and work out the offset for each instant you care about, from this route or from your own platform’s tz database.
Does the time zone API account for daylight saving time?
Yes, for the instant you ask about. The answer gives the standard offset and the daylight-saving shift separately and their sum as the offset to use, computed from the tz database’s history, so a timestamp last year or next summer gets the rules in force then rather than today’s.
Can I store time zone lookups in my own database?
Yes. The zone boundaries are derived from OpenStreetMap and licensed ODbL-1.0, which allows storing and using them. The obligation arrives if you make a database of those answers public: it is then offered under the same licence, with attribution. Keeping the zone beside your own customer records for internal use is ordinary use.
Why not use the time zone abbreviation?
Because abbreviations are not unique: CST names more than one zone on different continents, and some zones have no settled abbreviation at all. The abbreviation in the answer is for showing to a person. Store and compute with the IANA identifier, and never parse an abbreviation back into a zone.