From 08e04ed26e5ff38d04ba18560f5b7048aa734471 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 24 Apr 2022 22:19:49 +0100 Subject: [PATCH] dice: Honour fake time feature Really we should make this more pervasive, but this is what we need right now. Signed-off-by: Ian Jackson --- src/dice.rs | 2 +- src/utils.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dice.rs b/src/dice.rs index 687283e0..3f47b79a 100644 --- a/src/dice.rs +++ b/src/dice.rs @@ -249,7 +249,7 @@ impl Die { pub fn cooldown_remaining(&self, state: &State) -> Duration { let expires = &state.cooldown_expires; if_let!{ Some(FutureInstant(then)) = *expires; else return Ok(default()) }; - let now = Instant::now(); + let now = config().global_clock.now(); if now > then { return default() } let remaining = then - now; if remaining > self.cooldown_time { diff --git a/src/utils.rs b/src/utils.rs index 79cc592b..8fb3705a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -492,7 +492,7 @@ pub struct FutureInstant(pub Instant); impl Into for FutureInstant { fn into(self) -> Duration { - let now = Instant::now(); + let now = config().global_clock.now(); Instant::from(self).checked_duration_since(now).unwrap_or_default() } } @@ -505,7 +505,7 @@ impl TryFrom for FutureInstant { type Error = FutureInstantOutOfRange; #[throws(FutureInstantOutOfRange)] fn try_from(duration: Duration) -> FutureInstant { - let now = Instant::now(); + let now = config().global_clock.now(); now.checked_add(duration).ok_or(FutureInstantOutOfRange)?.into() } } -- 2.30.2