From: Ian Jackson Date: Sun, 24 Apr 2022 21:19:49 +0000 (+0100) Subject: dice: Honour fake time feature X-Git-Tag: otter-1.1.0~452 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=08e04ed26e5ff38d04ba18560f5b7048aa734471;p=otter.git 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 --- 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() } }