Crate chrono_simpletz

source ·
Expand description

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.with_ymd_and_hms(2000, 1, 1,12, 00, 00).unwrap();
let naive_time = NaiveDate::from_ymd_opt(2000, 1, 1).unwrap().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 FixedOffset 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|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.

Modules

Structs

  • Represent Fixed Timezone with zero sized type and const generics. HOUR and MINUTE must be in valid range(-23 <= HOUR <= 23 & MINUTE < 60), otherwise compile error will occur.

Type Aliases