#timezone #latitude #longitude #finder #time #convert #name

bin+lib tzf-rs

Fast convert longitude,latitude to timezone name

18 releases

new 0.4.8 Apr 12, 2024
0.4.7 Mar 16, 2024
0.4.5 Dec 29, 2023
0.4.4 Aug 19, 2023
0.1.3 Nov 28, 2022

#21 in Geospatial

Download history 142/week @ 2023-12-23 538/week @ 2023-12-30 378/week @ 2024-01-06 290/week @ 2024-01-13 500/week @ 2024-01-20 452/week @ 2024-01-27 525/week @ 2024-02-03 469/week @ 2024-02-10 559/week @ 2024-02-17 1376/week @ 2024-02-24 1394/week @ 2024-03-02 1573/week @ 2024-03-09 1425/week @ 2024-03-16 1082/week @ 2024-03-23 1168/week @ 2024-03-30 842/week @ 2024-04-06

4,796 downloads per month
Used in 3 crates

MIT license

155KB
387 lines

tzf-rs: a fast timezone finder for Rust. Rust Documentation

Time zone map of the world

[!NOTE]

This package uses simplified shape data so it is not entirely accurate around the border.

Build options

By default, the binary is built as well. If you don't want/need it, you can omit the default features and build like this:

cargo build --no-default-features

Or add in the below way:

cargo add tzf-rs --no-default-features

Best Practices

It's expensive to init tzf-rs's Finder/FuzzyFinder/DefaultFinder, so please consider reusing instances or creating one as a global variable. Below is a global variable example:

use lazy_static::lazy_static;
use tzf_rs::DefaultFinder;

lazy_static! {
    static ref FINDER: DefaultFinder = DefaultFinder::new();
}

fn main() {
    print!("{:?}\n", FINDER.get_tz_name(116.3883, 39.9289));
    print!("{:?}\n", FINDER.get_tz_names(116.3883, 39.9289));
}

For reuse, racemap/rust-tz-service provides a good example.

A Redis protocol demo could be used here: ringsaturn/redizone.

Performance

The tzf-rs package is intended for high-performance geospatial query services, such as weather forecasting APIs. Most queries can be returned within a very short time, averaging around 3,000 nanoseconds (about 1,000ns slower than with Go repo tzf. I will continue improving this - you can track progress here).

Here is what has been done to improve performance:

  1. Using pre-indexing to handle most queries takes approximately 1000 nanoseconds.
  2. Using a finely-tuned Ray Casting algorithm package ringsaturn/geometry-rs to verify whether a polygon contains a point.

That's all. There are no black magic tricks inside the tzf-rs.

Below is a benchmark run on global cities(about 14K), and avg time is about 3,000 ns per query:

test benches_default::bench_default_finder_random_city ... bench:       2,870 ns/iter (+/- 182)
Criterion result Pic
PDF
Regression

You can view more details from latest benchmark from GitHub Actions logs.

References

I have written an article about the history of tzf, its Rust port, and its Rust port's Python binding; you can view it here.

Bindings

LICENSE

This project is licensed under the MIT license. The data is licensed under the ODbL license, same as evansiroky/timezone-boundary-builder

Dependencies

~14MB
~71K SLoC