From 34f850e0cfc512e8437c00c5dedeef0c2b423357 Mon Sep 17 00:00:00 2001 From: Daniel Faust Date: Mon, 17 Oct 2022 20:00:15 +0200 Subject: [PATCH] Add chrono_tz support --- README.md | 4 ++++ fake/Cargo.toml | 1 + fake/README.md | 4 ++++ fake/src/impls/chrono_tz/mod.rs | 21 +++++++++++++++++++++ fake/src/impls/mod.rs | 2 ++ 5 files changed, 32 insertions(+) create mode 100644 fake/src/impls/chrono_tz/mod.rs diff --git a/README.md b/README.md index fd58e48..37e31ea 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,10 @@ If you want the date and time features from `chrono`: ```toml fake = { version = "2.5", features=['chrono']} ``` +If you want the timezone features from `chrono-tz`: +```toml +fake = { version = "2.5", features=['chrono-tz']} +``` If you want `http` faker features: ```toml fake = { version = "2.5", features=['http']} diff --git a/fake/Cargo.toml b/fake/Cargo.toml index 0356c1b..a4cb72c 100644 --- a/fake/Cargo.toml +++ b/fake/Cargo.toml @@ -18,6 +18,7 @@ dummy = { version = "0.4", path = "../dummy_derive", optional = true } rand = "0.8" random_color = { version="0.6", optional = true } chrono = { version = "0.4", features = ["std"], optional = true, default-features = false } +chrono-tz = { version = "0.6", optional = true } http = { version = "0.2", optional = true } semver = { version = "1", optional = true } uuid = { version = "1.2", features = ["v1", "v3", "v4", "v5"], optional = true } diff --git a/fake/README.md b/fake/README.md index 5674cc2..bac8335 100644 --- a/fake/README.md +++ b/fake/README.md @@ -21,6 +21,10 @@ If you want the date and time features from `chrono`: ```toml fake = { version = "2.5", features=['chrono']} ``` +If you want the timezone features from `chrono-tz`: +```toml +fake = { version = "2.5", features=['chrono-tz']} +``` If you want `http` faker features: ```toml fake = { version = "2.5", features=['http']} diff --git a/fake/src/impls/chrono_tz/mod.rs b/fake/src/impls/chrono_tz/mod.rs new file mode 100644 index 0000000..e50257c --- /dev/null +++ b/fake/src/impls/chrono_tz/mod.rs @@ -0,0 +1,21 @@ +use crate::{Dummy, Fake, Faker}; +use chrono_tz::{Tz, TZ_VARIANTS}; +use rand::Rng; + +impl Dummy for Tz { + fn dummy_with_rng(_: &Faker, rng: &mut R) -> Self { + let index: usize = (0..TZ_VARIANTS.len()).fake_with_rng(rng); + TZ_VARIANTS[index] + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn dummy_tz() { + let tz: Tz = Faker.fake(); + assert!(TZ_VARIANTS.contains(&tz)); + } +} diff --git a/fake/src/impls/mod.rs b/fake/src/impls/mod.rs index 5089e4c..a8a2e0f 100644 --- a/fake/src/impls/mod.rs +++ b/fake/src/impls/mod.rs @@ -4,6 +4,8 @@ pub mod bigdecimal; #[cfg(feature = "chrono")] pub mod chrono; +#[cfg(feature = "chrono-tz")] +pub mod chrono_tz; #[cfg(feature = "random_color")] pub mod color; #[cfg(feature = "rust_decimal")]