#timezone #chrono #time #date-time #zero #sized #typed

no-std chrono-simpletz

Simple Zero Sized Typed timezones for chrono

5 unstable releases

0.3.0 Jan 20, 2024
0.2.0 Dec 24, 2023
0.1.3 Apr 2, 2021
0.1.1 Apr 1, 2021
0.1.0 Apr 1, 2021

#245 in Date and time

Download history 16/week @ 2024-07-20 36/week @ 2024-07-27 15/week @ 2024-08-03 33/week @ 2024-08-10 13/week @ 2024-08-17 103/week @ 2024-08-24 2/week @ 2024-08-31 98/week @ 2024-09-07 71/week @ 2024-09-14 52/week @ 2024-09-21 120/week @ 2024-09-28 15/week @ 2024-10-05 34/week @ 2024-10-12 254/week @ 2024-10-19 31/week @ 2024-11-02

320 downloads per month

MIT license

36KB
591 lines

chrono-simpletz

Doc Crate

Simple Zero Sized Typed Utc timezones for chrono. This needs const generic (for rust >= 1.51 in stable).

use chrono::*;
use chrono_simpletz::TimeZoneZst;
use chrono_simpletz::known_timezones::*;
use std::mem::size_of_val;
//construct by new() or Default::default()
let p9 = UtcP9::new();
//size of UtcP9 is zero
assert_eq!(size_of_val(&p9), 0);
assert_eq!(&p9.to_string(), "+09:00");
assert_eq!(UtcP9::IS_IN_VALID_RANGE, true);
let time = p9.ymd(2000, 1, 1).and_hms(12, 00, 00);
let naive_time = NaiveDate::from_ymd_opt(2000, 1, 1).and_hms(3, 0, 0);
assert_eq!(time.naive_utc(), naive_time);
//same size as naive datetime
assert_eq!(size_of_val(&time),size_of_val(&naive_time));
let fixed = time.with_timezone(&p9.fix());
assert_eq!(time, fixed);
//same Display with FixedOffset
assert_eq!(time.to_string(), fixed.to_string());
// smaller size than fixed offset size
assert!(size_of_val(&time) < size_of_val(&fixed) )

features

std (default)

with std

clock (default)

Adds today and now function for TimeZoneZst.

serde

serde_ts_(seconds|milliseconds|microseconds|nanoseconds)(|\_option)

Adds modules for de/serialize functions to use with de/serialize_with function.

serde_ts_rfc3339(|\_option)

Adds modules for de/serialize functions to use with de/serialize_with function. You need this when you want to de/serialize like DateTime<Utc>, because DateTime<UtcZtc<H,M>> cannot impl De/Serialize.

Dependencies

~1–5.5MB
~25K SLoC