A tool to easily work with timezone lookups via a binary, a library, or a server.

Related tags

Command-line rtz
Overview

Build and Test codecov Version Crates.io GitHub all releases npm Documentation Rust License:MIT

rtz

A self-contained geo lookup library / binary / server for Rust / JS (via WASM) (free server) using data from the Natural Earth and OpenStreetMap datasets.

Free Server

The server is deployed to four regions across the globe, and is available at tz.twitchax.com. Each region is currently capable of supporting around 8,000 RPS, and is deployed to the following regions: sea, iad, ams, hkg.

In addition, the server will now generally attempt to not break backwards compatibility within an api version. This means that the server will (attempt to) not change the response format for a given api version, and will (attempt to) not remove any fields from the response. This does not mean that the server will not add fields to the response, but it will (attempt to) not remove them.

Requests take the form of http://tz.twitchax.com/api/v1/osm/tz/{lng}/{lat}. You can also check out the swagger docs to explore other endpoints and versioning strategy.

Example request:

$ curl http://tz.twitchax.com/api/v1/osm/tz/30/30

[{"id":12,"identifier":"Africa/Cairo","shortIdentifier":"EEST","offset":"UTC+03:00","rawOffset":10800,"rawBaseOffset":7200,"rawDstOffset":3600,"zone":3.0,"currentTime":"2023-07-25T23:39:59.385469400+03:00"}]

HTTPS is also available, but is not recommended due to the performance overhead for the client and the server, and the lack of sensitive data being transmitted.

Binary Usage

Install

Windows:

$ iwr https://github.com/twitchax/rtz/releases/latest/download/rtz_x86_64-pc-windows-gnu.zip
$ Expand-Archive rtz_x86_64-pc-windows-gnu.zip -DestinationPath C:\Users\%USERNAME%\AppData\Local\Programs\rtz

Mac OS (Apple Silicon):

$ curl -LO https://github.com/twitchax/rtz/releases/latest/download/rtz_aarch64-apple-darwin.zip
$ unzip rtz_aarch64-apple-darwin.zip -d /usr/local/bin
$ chmod a+x /usr/local/bin/rtz

Linux:

$ curl -LO https://github.com/twitchax/rtz/releases/latest/download/rtz_x86_64-unknown-linux-gnu.zip
$ unzip rtz_x86_64-unknown-linux-gnu.zip -d /usr/local/bin
$ chmod a+x /usr/local/bin/rtz

Cargo:

$ cargo install rtz

NPM:

$ npm install --save rtzweb

Help Docs

$ rtz

A tool to easily work with geo lookups via a binary, a library, or a server.

Usage: rtz [COMMAND]

Commands:
  resolve-ned  Resolve a timezone from a lng,lat pair using the NED dataset
  resolve-osm  Resolve a timezone from a lng,lat pair using the OSM dataset
  serve        Serve the timezone API
  help         Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help
  -V, --version  Print version

Resolve a Time Zone

$ rtz resolve-ned "-87.62,41.88"

Identifier:      America/Chicago
UTC Offset:      UTC-06:00
Offset Seconds:  -21600
Description:     Canada (almost all of Saskatchewan), Costa Rica, El Salvador, Ecuador (Galapagos Islands), Guatemala, Honduras, Mexico (most), Nicaragua,
DST Description: Canada (Manitoba), United States (Illinois, most of Texas)

Run with Wasmer

wasmer run twitchax/rtz@latest -- resolve-ned 30,30

Run the Server

$ cargo install rtz --features web
$ rtz serve
$ docker run -it --rm -p 8082 twitchax/rtx

Library Usage

Add this to your Cargo.toml:

[dependencies]
rtz = "*" #choose a version

Examples

use rtzlib::NedTimezone;
use rtzlib::CanPerformGeoLookup;

// Query a time zone for a given `(lng,lat)`.
assert_eq!(
    NedTimezone::lookup(-121., 46.)[0]
        .identifier
        .as_ref()
        .unwrap(),
    "America/Los_Angeles"
);

JS Usage

The npm package is available here.

First, load the module as you would any other ES module.

import * as rtz from 'rtzweb/rtzlib.js';

Then, you can use the library similarly as you would in Rust.

let tz = rtz.getTimezoneNed(-121, 46);
tz.identifier; // "America/Los_Angeles"

Feature Flags

The library and binary both support various feature flags. Of most important note are:

  • Top-Level:
    • default = ["cli"]
    • full = ["tz-ned", "self-contained"]
  • Datasets:
    • tz-ned: enables the Natural Earth time zone dataset, and the associated produced library functions.
    • tz-osm: enables the OpenStreetMap time zone dataset, and the associated produced library functions.
  • Binary configuration:
    • cli: enables the CLI features, and can be removed if only compiling the library.
    • self-contained: enables the self-contained features, which build with datasets embedded into the binary.
    • double-precision: uses f64s every for Geometry and Polygon data types, which is more accurate but fatter than f32s.
    • unsimplified: produces unsimplified data caches. Requires more binary / memory overhead, but is more accurate. Uses the level of detail from the original dataset. The default is to simplify to an epsilon of 0.0001.
    • extrasimplified: produces extrasimplified data caches. Requires less binary / memory overhead, but is less accurate. This sets the simplification epsilon to 0.01.
  • Special Modifiers:
    • wasm: enables the WASM features, and is required to build an NPM package via wasm-pack.
    • web = ["full"]: enables the serve subcommand, which starts a Rocket web server that can respond to time zone requests.
  • Other Considerations:
    • wasm / wasi builds currently do not play nice with reqwest and zip, so the wasm / wasi builds require the self-contained feature.

Performance

General

This implementation trades binary size for performance by employing an in-binary cache that improves average timezone resolution by about 96x, and worst-case resolution by about 10x. The cache is generated from the Natural Earth dataset, and is included in the binary. The cache is generated by the generate subcommand, and is stored in the assets directory.

Bench

Free Server

Below is the sample performance to resolve a time zone from a (lng,lat) pair to one of the data centers using a concurrency of 1,000, achieving 8,000 RPS.

Drill Perf 1

Below is the sample performance to resolve a time zone from a (lng,lat) pair to one of the data centers using a concurrency of 100, achieving an average response time of 24 ms.

Drill Perf 2

Test

cargo test --features full --features web

Bench

cargo bench --features full --features web

License

MIT

You might also like...
dovi_meta is a CLI tool for creating Dolby Vision XML metadata from an encoded deliverable with binary metadata.

dovi_meta dovi_meta is a CLI tool for creating Dolby Vision XML metadata from an encoded deliverable with binary metadata. Building Toolchain The mini

An experimental, work-in-progress PAM module for Tailscale

Experimental Tailscale PAM Module This is a very very experimental Tailscale PAM module that allows you to SSH using your Tailscale credentials. This

Dura - You shouldn't ever lose your work if you're using Git

Dura Dura is a background process that watches your Git repositories and commits your uncommitted changes without impacting HEAD, the current branch,

Work-in-progress Rust application that converts C++ header-only libraries to single self-contained headers.

unosolo Work-in-progress Rust application that converts C++ header-only libraries to single self-contained headers. Disclaimer This is my first Rust p

Work-in-progress software for managing the Azeron keypad on any operating system.
Work-in-progress software for managing the Azeron keypad on any operating system.

azeron-cli A small, unfinished CLI application intended to manage the Azeron Cyborg. The code is still in a very messy state and doesn't look very rus

Work in progress NCBI's Common Tree alternative in the terminal

Lomanai Usage lomanai --species 'Mus musculus' --species 'Homo sapiens' # Mammalia # ++Rodentia # | \-Mus musculus # \+Primates # \-Homo sapien

A work-in-progress static analyser.

Statan Statan is an early-stage static analyser for PHP and PXP projects. It is being developed in public and the journey is documented on my blog. Th

Work out how far apart things should be (very quickly)
Work out how far apart things should be (very quickly)

Kern determiner Work out how far apart things should be (very quickly) kerndeterminer is a Rust-based library for determining a kern value between two

Work with bioinformatic files using Arrow, Polars, and/or DuckDB

biobear is a Python library designed for reading and searching bioinformatic file formats, using Rust as its backend and producing Arrow Batch Readers

Comments
  • Use more up-to-date timezone data

    Use more up-to-date timezone data

    The current data, coming from Natural Earth (which in turns pulls from the CIA Factbook May 2012). This means the current data is about a decade out-of-date.

    Instead, you should probably use https://github.com/evansiroky/timezone-boundary-builder, which is constantly kept up-to-date on an ongoing basis.

    opened by phayes 7
  • Clarify the meaning of fields in `Timezone`

    Clarify the meaning of fields in `Timezone`

    The documentation for Timezone is very terse and doesn't really explain what any of the fields mean. I presume these fields are taken from the Natural Earth dataset, but I couldn't find the relevant documentation for the dataset online.

    It would be useful if either the meaning of these fields was clarified or if the docs of this crate linked to relevant documentation from Natural Earth that explains their meaning.

    Some of the specific questions I had:

    • Is friendly_name the IANA TZ identifier?
    • Why is friendly_name an Option? What does it mean when it is None?
    • What is zone_str? Is it just zone_num as a string and if so why does it's example value differ from zone_num?
    • Why is zone_num an Option but offset_str isn't? What does it mean when zone_num is None?
    opened by FeldrinH 2
  • Clarify when to use `get_timezone` vs `get_timezone_via_full_lookup`

    Clarify when to use `get_timezone` vs `get_timezone_via_full_lookup`

    The get_timezone documentation states that it performs a 'cache-driven' lookup. Presumably this is faster than a full lookup, so why should a full lookup ever be used? Are there locations where the cache gives an incorrect result? It would be useful if the documentation made it clear what the use case and tradeoff of each method is.

    opened by FeldrinH 2
  • Clarify when to use `get_timezone` vs `get_timezone_via_full_lookup`

    Clarify when to use `get_timezone` vs `get_timezone_via_full_lookup`

    The get_timezone documentation states that it performs a 'cache-driven' lookup. Presumably this is faster than a full lookup, so why should a full lookup ever be used? Are there locations where the cache gives an incorrect result? It would be useful if the documentation made it clear what the use case and tradeoff of each method is.

    opened by FeldrinH 1
Releases(v0.4.2)
Owner
Aaron Roney
Aaron Roney
Sero is a web server that allows you to easily host your static sites without pain. The idea was inspired by surge.sh but gives you full control.

sero Lightning-fast, static web publishing with zero configuration and full control ?? Table Of Contents ?? Table Of Contents ?? Tools ❓ About The Pro

Dmitry Miasnenko 6 Nov 13, 2023
A Content Discovery Tool insipired from Feroxbuster. Work In Progress

monologue A Content Discovery Tool written in Rust, insipired from Feroxbuster. Installation Dependencies OpenSSL (If You are on linux). Rust programm

Voyage 3 Jul 20, 2023
dye is a tool to easily color text in shell.

Dye dye is a tool to easily color text in shell. Usage See the gif below to see these commands in action. echo $(dye --red WARN) This tool will knock

Kurt Wolf 15 Nov 1, 2022
A CLI companion tool for paste.misterio.me, allowing you to easily upload and manage your pastes

This is a CLI companion tool for paste.misterio.me, allowing you to easily upload and manage your pastes, as well as download any pastes you want.

Gabriel Fontes 1 Jan 26, 2022
A command line tool for easily generating multiple versions of a configuration file from a single template

MultiConf A command line tool for easily generating multiple versions of a configuration file from a single template. Why? I'm a big fan of the i3 win

Ian Clarke 4 Dec 10, 2022
A command-line tool to easily kill processes running on a specified port.

killport killport is a command-line utility for killing processes listening on specific ports. It's designed to be simple, fast, and effective. The to

Francisco Jiménez Cabrera 6 Mar 29, 2023
tmplt is a command-line interface tool that allows you to quickly and easily set up project templates for various programming languages and frameworks

tmplt A User Friendly CLI Tool For Creating New Projects With Templates About tmplt is a command-line tool that lets users quickly create new projects

Humble Penguin 35 Apr 8, 2023
Cli tool for git productivity written in Rust and packaged for consumption via NPM

crust ?? cli tool for git productivity written in Rust and packaged for consumption via NPM This repo is identical with @skyneticist/golee in terms of

null 2 Jul 30, 2022
A tool to control the fan speed by monitoring the temperature of CPU via IPMI.

ipmi-fan-control A tool to control the fan speed by monitoring the temperature of CPU via IPMI. Why Our Dell R730 server's iDRAC is not works as expec

yinheli 9 Dec 29, 2022
🦀️atos for linux by rust - A partial replacement for Apple's atos tool for converting addresses within a binary file to symbols.

atosl-rs ??️ atos for linux by rust - A partial replacement for Apple's atos tool for converting addresses within a binary file to symbols. tested on

everettjf 60 Dec 29, 2022