Skip to content

Commit

Permalink
Merge pull request #204 from m4tx/master
Browse files Browse the repository at this point in the history
feat: add Precision::<N> support for chrono::NaiveDateTime
  • Loading branch information
cksac authored Nov 25, 2024
2 parents 30de066 + 7414661 commit df5fb53
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions fake/src/impls/chrono/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ where
}
}

impl<const N: usize> Dummy<Precision<N>> for NaiveDateTime
where
Precision<N>: AllowedPrecision,
{
fn dummy_with_rng<R: Rng + ?Sized>(precision: &Precision<N>, rng: &mut R) -> Self {
let date = Faker.fake_with_rng(rng);
let time = Precision::<N>::fake_with_rng(precision, rng);
NaiveDateTime::new(date, time)
}
}

impl<Tz, const N: usize> Dummy<Precision<N>> for DateTime<Tz>
where
Tz: TimeZone + Dummy<Faker>,
Expand Down
5 changes: 4 additions & 1 deletion fake/tests/determinism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ mod color {
// Chrono
#[cfg(feature = "chrono")]
mod chrono {
use fake::{faker::chrono::raw::*, locales::*, Fake};
use fake::{chrono::Precision, faker::chrono::raw::*, locales::*, Fake};
use rand::SeedableRng as _;

fn lo() -> chrono::DateTime<chrono::Utc> {
Expand All @@ -121,6 +121,9 @@ mod chrono {
check_determinism! { l10d DateTimeBetween; String, fake_date_time_between_en, fake_date_time_between_fr, fake_date_time_between_cn, fake_date_time_between_tw, fake_date_time_between_jp, fake_date_time_between_br, lo(), hi() }
check_determinism! { l10d Duration; ::chrono::Duration, fake_duration_en, fake_duration_fr, fake_duration_cn, fake_duration_tw, fake_duration_jp, fake_duration_br }
check_determinism! { l10d Time; String, fake_time_en, fake_time_fr, fake_time_cn, fake_time_tw, fake_time_jp, fake_time_br }
check_determinism! { one fake_naive_time_precision, ::chrono::NaiveTime, Precision::<6> }
check_determinism! { one fake_naive_date_time_precision, ::chrono::NaiveDateTime, Precision::<6> }
check_determinism! { one fake_date_time_precision, ::chrono::DateTime<::chrono::Utc>, Precision::<6> }
}

// time
Expand Down

0 comments on commit df5fb53

Please sign in to comment.