x-hgg-x/tz-rs


A pure Rust reimplementation of libc functions localtime, gmtime and mktime.

License: Apache-2.0

Language: Rust

Keywords: date, no-std, rust, time, timezone


tz-rs

version Minimum supported Rust version Documentation

A pure Rust reimplementation of libc functions localtime, gmtime and mktime.

This crate allows to convert between a Unix timestamp and a calendar time expressed in the proleptic gregorian calendar with a provided time zone.

Time zones are provided to the library with a POSIX TZ string which can be read from the environment.

Two formats are currently accepted for the TZ string:

  • std offset[dst[offset][,start[/time],end[/time]]] providing a time zone description,
  • file or :file providing the path to a TZif file, which is absolute or relative to the system timezone directory.

See also the Linux manual page of tzset(3) and the glibc documentation of the TZ environment variable.

Context

Calls to libc localtime_r and other related functions from Rust are not safe in a multithreaded application, because they may internally set the TZ environment variable with the setenv function, which is not thread-safe.

See RUSTSEC-2020-0071 and RUSTSEC-2020-0159 for more information.

Documentation

Documentation is hosted on docs.rs.

Platform support

This crate is mainly intended for UNIX platforms.

Since the time zone database files are not included in this crate, non-UNIX users can download a copy of the database on the IANA site and compile the time zone database files to a local directory.

The database files can then be read by specifying an absolute path in the TZ string:

TimeZone::from_posix_tz(format!("{local_database_dir}/usr/share/zoneinfo/Pacific/Auckland"))?;

Note that the determination of the local time zone with this crate is not supported on non-UNIX platforms.

Alternatively, a crate like tzdb can be used, which statically provides existing time zone definitions for this crate, and supports finding the local time zone for all Tier 1 platforms.

Date time formatting (equivalent of libc strftime function)

This crate doesn't provide custom date time formatting support, but the custom-format crate can be used to provide custom format specifiers to the standard library formatting macros.

Compiler support

Requires rustc 1.81 .

License

This project is licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Project Statistics

Sourcerank 10
Repository Size 267 KB
Stars 169
Forks 5
Watchers 5
Open issues 0
Dependencies 0
Contributors 6
Tags 29
Created
Last updated
Last pushed

Top Contributors See all

x-hgg-x René Kijewski Ben Naylor Ryan Lopopolo dependabot[bot] T•Ø•R•Ü•S

Packages Referencing this Repo

tz-rs
A pure Rust reimplementation of libc functions localtime, gmtime and mktime.
Latest release 0.7.0 - Updated - 169 stars

Recent Tags See all

v0.7.0 September 14, 2024
v0.6.14 August 13, 2022
v0.6.13 August 12, 2022
v0.6.12 July 26, 2022
v0.6.11 June 30, 2022
v0.6.10 June 26, 2022
v0.6.9 April 14, 2022
v0.6.8 April 13, 2022
v0.6.7 March 23, 2022
v0.6.6 March 21, 2022
v0.6.5 March 05, 2022
v0.6.4 March 03, 2022
v0.6.3 March 02, 2022
v0.6.2 March 02, 2022
v0.6.1 February 28, 2022

Something wrong with this page? Make a suggestion

Last synced: 2024-09-14 13:20:08 UTC

Login to resync this repository