From b1ef5941100b40cf2c43bb7aab08b2c426e35c9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 5 Aug 2026 22:33:46 +0300 Subject: [PATCH] =?UTF-8?q?=E2=8F=B0=20fix:=20read=20the=20one=20clock=20i?= =?UTF-8?q?n=20the=20meal=20past-day=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The two test helpers 7c5bc9d added read `chrono::Utc::now()` directly, which `clippy.toml` denies: `Timestamp::now`/`today_utc` is the crate's single wall-clock source, and that is what makes "no local/UTC mix" checkable at all. A denied lint left standing in tests quietly retires the guard for the whole crate. Both go through `Timestamp::today_utc()` — which returns the `NaiveDate` these wanted anyway — and yesterday is now `pred_opt()` rather than a `chrono:: Duration` subtraction. Same dates, one clock. No `#[allow]` was needed: the crate-native helper covers both cases exactly. --- src/domain/meal_booking.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/domain/meal_booking.rs b/src/domain/meal_booking.rs index c3af73d..a2d230b 100644 --- a/src/domain/meal_booking.rs +++ b/src/domain/meal_booking.rs @@ -1344,11 +1344,12 @@ mod tests { assert!(check_cutoff(&past, &lunch(), &cutoff(Some(60), Some(720))).is_err()); } + /// Through the crate's one clock ([`Timestamp::today_utc`]), never + /// `chrono::Utc::now` — the guard under test compares against that same + /// clock, and a test reading a second one is how a timezone mix gets back + /// in (`clippy.toml` denies it, tests included). fn today() -> String { - chrono::Utc::now() - .date_naive() - .format("%Y-%m-%d") - .to_string() + Timestamp::today_utc().format("%Y-%m-%d").to_string() } /// The day being over is not the cutoff. It binds with no @@ -1357,7 +1358,9 @@ mod tests { /// — and it never binds today, at any hour. #[test] fn the_past_day_guard_is_not_the_serving_hour_cutoff() { - let yesterday = (chrono::Utc::now().date_naive() - chrono::Duration::days(1)) + let yesterday = Timestamp::today_utc() + .pred_opt() + .expect("there is a day before today") .format("%Y-%m-%d") .to_string(); assert!(check_day_not_past(&MenuDate::try_new(&yesterday).unwrap()).is_err());