Crates.io | time-tz |
lib.rs | time-tz |
version | 3.0.0-rc.5.0.0 |
source | src |
created_at | 2022-02-07 23:28:49.822616 |
updated_at | 2024-03-02 13:04:14.748787 |
description | Implementation of tz database (IANA) for the time Rust crate. |
homepage | |
repository | https://github.com/Yuri6037/time-tz |
max_upload_size | |
id | 528712 |
size | 1,957,631 |
An implementation of the tz database for the time-rs Rust crate.
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).
assume_timezone
member function to any PrimitiveDateTime
.to_timezone
member function to any OffsetDateTime
.timezones::get_by_name
function to get a timezone by name.system
feature).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
}