#timezone #iana #operating-system #olson

yanked system_tz

Current timezone from the operating system

0.4.0 Apr 11, 2023
0.3.0 Apr 11, 2023
0.2.0 Apr 11, 2023
0.1.0 Apr 11, 2023

#23 in #iana

40 downloads per month

Apache-2.0

26KB
392 lines

system_tz

Version Documentation License

This utility crate provides a single trait SystemTz which exposes the system_tz() method allowing to get the timezone from the operating system.

Should support the following operating system families: unix, windows and wasm.

Effectively tested on:

  • 2023-04-11: Debian GNU/Linux 11 (bullseye)
  • 2023-04-11: Microsoft Windows 11
  • ...

Valid timezones are represented with chrono_tz::Tz based on IANA Time Zone Database (Olson names).

On Microsoft Windows, because it uses of a special naming convention, the method relies on WindowsZones, a dataset maintained by the Unicode Common Locale Data Repository (CLDR), which is downloaded and built into a static global object during compilation.

Safety

Attention was given to provide safe implementation (no unwrap() or expect()) but note that on windows target:

  • the build script is faillible (it is designed to panic on error)
  • 1 unsafe is used by the fallback method because of windows API.

Command-line interface

The crate provides a very basic binary which will print the system timezone on invokation.

Installation

Refer to the official documentation for installing the cargo package manager, and then run the following command from a terminal:

$ cargo install system_tz

Usage

The interface doesn't require any argument.

$ tz
Europe/Paris

Contribute

Contributions to the project are most welcome. In particular, please let us known whether it works on your device so we can improve the implementation and extend support.

Pull request imply agreement to the Developer's certificate of origin (DCO-1.1).

Credits

Dependencies

~2–44MB
~637K SLoC