Skip to content

About

Offline timezone lookup for WGS84 coordinates, with no polygon simplification - so the answer stays correct at timezone borders.

Topics

Resources

Code of conduct

Contributing

Stars

542 stars

Watchers

7 watching

Forks

Latest commit

 

History

1,049 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

timezonefinder

Coordinate to IANA timezone lookup

Python package for offline timezone lookup of WGS84 coordinates, with no polygon simplification - so the answer stays correct at timezone borders.

build status documentation status wheel pre-commit total PyPI downloads monthly PyPI downloads latest version on PyPI latest version on conda-forge supported python versions DOI linted and formatted with ruff

Compared with the alternatives, it puts accuracy at timezone borders first while keeping lookups fast, and it runs with or without a C compiler. For research data, it turns UTC timestamps recorded with coordinates into local time offline and reproducibly - see the statement of need.

Quick Guide

pip install timezonefinder

This builds a small C extension for the point-in-polygon test. Without a compiler, install the Numba extra instead (pip install timezonefinder[numba]). Free-threaded Python builds are supported: the GIL stays disabled, so lookups run on all threads at once (concurrency).

The boundary data comes as the separate timezonefinder-data package, so new datasets ship without a code release. A dataset update can change results, so pin a version (pip install timezonefinder "timezonefinder-data==<version>") when results must stay reproducible; see result stability.

from timezonefinder import timezone_at

tz = timezone_at(lng=13.358, lat=52.5061)  # 'Europe/Berlin'

# For many lookups, reuse one instance (the context manager frees its data):
from timezonefinder import TimezoneFinder

with TimezoneFinder(in_memory=True) as tf:
    tz = tf.timezone_at(lng=13.358, lat=52.5061)  # 'Europe/Berlin'

    # Batch lookups take one array per axis:
    names = tf.timezone_names_at(lngs=[13.358, 2.3522], lats=[52.5061, 48.8566])
    # ['Europe/Berlin', 'Europe/Paris']

The full dataset with over 400 timezone names is used by default. A smaller "timezones-now" dataset is available via update_data.sh (details).

How it works

A lookup first finds the point's cell in a precomputed grid index. Most cells lie inside a single timezone, so the index answers directly without touching any geometry. Only where zones meet does the lookup run an exact point-in-polygon test against the few zones listed for that cell, on coordinates stored to about 1 cm. The architecture page walks through the full pipeline, and data format documents the index and the binary layouts.

The boundary polygons are never simplified, so border accuracy is limited only by the source dataset; the grid index is what keeps full-resolution geometry fast. Why no simplification explains the trade-off.

The dataset includes ocean zones, so every coordinate on earth gets a timezone - use timezone_at_land() to tell land from sea. Where zones overlap, timezone_at() returns the smaller one and timezones_at() returns all of them.

Performance

Hundreds of thousands of lookups per second on a single core for uniformly random query points. The exact figure depends on the backend, the machine and the dataset version, so it lives in the benchmark reports, each stating the configuration it was measured in.

The point-in-polygon test has three backends - the C extension, Numba and pure Python - and all of them return identical answers: a missing compiler costs speed, never results. The acceleration path comparison measures which one is fastest.

Low memory by default. The boundary coordinates are memory-mapped, so only the pages a lookup reads become resident and the operating system can reclaim them under pressure. TimezoneFinder(in_memory=True) trades memory for speed; the memory report measures both modes.

Engineering notes

  • Architecture - the lookup pipeline, the acceleration backends, and the ceilings this package deliberately does not exceed
  • Data Format - binary layouts, coordinate scaling and the shortcut index
  • Testing philosophy - the tests that exist because a rule needed a failure mode, plus the property-based suite and the version/backend matrix
  • How it ships - abi3 wheels, three libc targets, and the checks that stop a broken wheel reaching PyPI
  • Result stability - which answers a dataset or code update can change, and which it cannot
  • Alternatives - the trade-offs against tzfpy, a faster Rust-based package, and when to choose it instead
  • Changelog

Used by

GitHub's dependency graph lists thousands of repositories and hundreds of published packages that depend on timezonefinder, among them:

Contributing

Looking for maintainers. Reach out if you want to contribute!

CONTRIBUTING.md is the entrypoint for human and AI coding-agent contributors alike. Its routing table sends each task to the few files under contributing/ it needs: coding and testing rules, the development and CI workflow, the benchmarking gates, step-by-step workflows for releases, reviews and improvement passes, and the recorded design decisions.

References

Citing

To cite timezonefinder, use the DOI 10.5281/zenodo.23579731, which Zenodo resolves to the latest release, or the "Cite this repository" button on GitHub, which reads CITATION.cff. As BibTeX:

@software{kissinger_timezonefinder,
  author = {Kissinger, Jannik},
  title = {timezonefinder},
  url = {https://github.com/jannikmi/timezonefinder},
  doi = {10.5281/zenodo.23579731}
}

In a methods section, also state the timezonefinder and timezonefinder-data versions you used: a data release can move answers, and TimezoneFinder.data_version names the boundary release a finder answers from (see result stability).

LICENSE

timezonefinder is licensed under the MIT license.

The data ships in the separate timezonefinder-data distribution and is licensed under the ODbL license, following the base dataset from evansiroky/timezone-boundary-builder.

About

Offline timezone lookup for WGS84 coordinates, with no polygon simplification - so the answer stays correct at timezone borders.

Topics

Resources

Code of conduct

Contributing

Stars

542 stars

Watchers

7 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages