Skip to content

Commit

Permalink
Merge pull request #105 from dfaust/master
Browse files Browse the repository at this point in the history
Add chrono_tz support
  • Loading branch information
cksac authored Oct 26, 2022
2 parents 4688c88 + 34f850e commit 67cf903
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']}
Expand Down
1 change: 1 addition & 0 deletions fake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 4 additions & 0 deletions fake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']}
Expand Down
21 changes: 21 additions & 0 deletions fake/src/impls/chrono_tz/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crate::{Dummy, Fake, Faker};
use chrono_tz::{Tz, TZ_VARIANTS};
use rand::Rng;

impl Dummy<Faker> for Tz {
fn dummy_with_rng<R: Rng + ?Sized>(_: &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));
}
}
2 changes: 2 additions & 0 deletions fake/src/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit 67cf903

Please sign in to comment.