From 7414661e15da393b0c4a45dcdd81f8e57c70b459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Ma=C4=87kowski?= Date: Tue, 19 Nov 2024 22:40:01 +0100 Subject: [PATCH] feat: add Precision:: support for chrono::NaiveDateTime --- fake/src/impls/chrono/mod.rs | 11 +++++++++++ fake/tests/determinism.rs | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/fake/src/impls/chrono/mod.rs b/fake/src/impls/chrono/mod.rs index c6b2605..681544d 100644 --- a/fake/src/impls/chrono/mod.rs +++ b/fake/src/impls/chrono/mod.rs @@ -124,6 +124,17 @@ where } } +impl Dummy> for NaiveDateTime +where + Precision: AllowedPrecision, +{ + fn dummy_with_rng(precision: &Precision, rng: &mut R) -> Self { + let date = Faker.fake_with_rng(rng); + let time = Precision::::fake_with_rng(precision, rng); + NaiveDateTime::new(date, time) + } +} + impl Dummy> for DateTime where Tz: TimeZone + Dummy, diff --git a/fake/tests/determinism.rs b/fake/tests/determinism.rs index a030768..affa68f 100644 --- a/fake/tests/determinism.rs +++ b/fake/tests/determinism.rs @@ -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 { @@ -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