#timezone #date-time #time #tz #iana #member #name

time-tz

Implementation of tz database (IANA) for the time Rust crate

17 releases (5 stable)

3.0.0-rc.5.0.0 Mar 2, 2024
2.0.0 Jul 22, 2023
1.0.3 Jun 10, 2023
1.0.2 May 22, 2022
0.5.2 Mar 11, 2022

#28 in Date and time

Download history 5558/week @ 2024-07-22 5929/week @ 2024-07-29 5244/week @ 2024-08-05 4788/week @ 2024-08-12 5799/week @ 2024-08-19 6124/week @ 2024-08-26 5221/week @ 2024-09-02 5316/week @ 2024-09-09 8405/week @ 2024-09-16 9979/week @ 2024-09-23 7143/week @ 2024-09-30 9349/week @ 2024-10-07 9075/week @ 2024-10-14 9763/week @ 2024-10-21 7792/week @ 2024-10-28 8664/week @ 2024-11-04

35,850 downloads per month
Used in 27 crates (20 directly)

BSD-3-Clause

635KB
10K SLoC

C 7K SLoC // 0.2% comments Rust 1.5K SLoC // 0.2% comments AWK 1K SLoC // 0.2% comments Korn shell 690 SLoC // 0.1% comments Shell 36 SLoC // 0.1% comments

time-tz

An implementation of the tz database for the time-rs Rust crate.

chat

This implementation is based off of chrono-tz (https://github.com/chronotope/chrono-tz) but uses time-rs instead of chrono. This is designed to replace use of chono dependency which is impacted by CVE-2020-26235 (localtime_r thread safety issue linked to std::env::set_var).

Features

  • Injects an assume_timezone member function to any PrimitiveDateTime.
  • Injects a to_timezone member function to any OffsetDateTime.
  • Provides a timezones::get_by_name function to get a timezone by name.
  • Supports finding the closest IANA match from a windows timezone name.
  • Supports obtaining system's current timezone (through the system feature).

Usage

use time::macros::datetime;
use time_tz::{PrimitiveDateTimeExt, OffsetDateTimeExt, timezones};

fn main()
{
    // ===========================================
    //  Create a new datetime in a given timezone
    // ===========================================
    
    // First we have to get the source timezone:
    let london = timezones::db::europe::LONDON;

    // Now we can create a primitive date time and call the extension function:
    let dt = datetime!(2016-10-8 17:0:0).assume_timezone_utc(london);


    // ===========================
    //  Convert to a new timezone
    // ===========================

    // First we get the target timezone:
    let berlin = timezones::db::europe::BERLIN;

    // Now we can convert (again by calling an extension function):
    let converted = dt.to_timezone(berlin);

    // ... do something with converted
}

Dependencies

~1–13MB
~122K SLoC