#timezone #zone #time

zone-detect

Rust version of the ZoneDetect C library

4 releases (2 stable)

1.0.1 Mar 17, 2024
1.0.0 Sep 6, 2021
0.2.0 Jan 27, 2020
0.1.0 Jan 25, 2020

#78 in Date and time

Download history 57/week @ 2024-07-25 9/week @ 2024-08-01 6/week @ 2024-09-19 3/week @ 2024-09-26 2/week @ 2024-10-03

102 downloads per month

BSD-3-Clause

3.5MB
946 lines

zone-detect

crates.io Documentation

This is a Rust version of the ZoneDetect C library. The initial conversion was done with c2rust, then manually cleaned up (it no longer contains any unsafe code).

This crate can be used to look up the country and timezone of any location on Earth.

Running the example

$ cargo run --example demo data/timezone21.bin 35.0715 -82.5216
zone 0: ZoneMatch {
    kind: InZone,
    zone: Zone {
        polygon_id: 1458,
        meta_id: 3199,
        fields: {
            "CountryAlpha2": "US",
            "CountryName": "United States",
            "TimezoneIdPrefix": "America/",
            "TimezoneId": "New_York",
        },
    },
}

Data source

The database containing the location and timezone data is in data/timezone21.bin. It can be updated as follows:

git clone https://github.com/BertoldVdb/ZoneDetect
cd ZoneDetect/database/builder
./makedb.sh
cp out_v1/timezone21.bin zone-detect-rs/data/timezone21.bin

Testing

There's a slow test that generates random values and compares the output between ZoneDetect and zone-detect-rs.

# Make sure the demo is built first; just run `make` in the ZoneDetect repo.

ZONEDETECT_DEMO=../ZoneDetect/demo cargo test -- --ignored

Dependencies