Tiny Rust Timezone — GPS to timezone for embedded.
trtz allows querying a timezone for any given GPS location using the datasets from
timezone-boundary-builder.
In contrast to crates like rtz or tzf-rs, trtz
mainly focuses on keeping the dataset as small as possible in order to work on embedded devices like an ESP-32.
This is achieved by rasterizing the full dataset to a grid and compressing that data with simple run-length encoding.
There are multiple datasets available, each with different grid sizes, so you can choose wichever suits you best
considering size, performance and usecase (see Feature Flags).
Add the dependency with your desired dataset.
cargo add trtz -F variant-now,grid-scale-4Then you can query timezone IDs with [find_tz]:
let tz = trtz::find_tz(-31.854739354017354, 128.1822207301782);
assert_eq!(Some("Australia/Eucla"), tz);trtz uses the data from timezone-boundary-builder.
They provide three different datasets of different sizes for different usecases, and each either with or without oceans
included. The with-oceans feature is enabled by default and switches to the datasets with oceans. For the specific
variant, one of these features must be enabled:
variant-comprehensive: largest, only necessary for historical datavariant-1970: also large, valid for all timestamps since 1970variant-now: smallest, fully sufficient for lookups of current local time
Additionally, multiple different grid scales can be selected to further control the dataset size. The sizes are specified as fractions of 1° by 1°, so e.g. a grid scale of 4 would have each grid cell be 0.25° by 0.25° in size. The available sizes are:
grid-scale-1: approx. up to 111 km side lengthsgrid-scale-2: approx. up to 56 km side lengthsgrid-scale-4: approx. up to 28 km side lengthsgrid-scale-6: approx. up to 19 km side lengths