chiark / gitweb /
dice: Honour fake time feature
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 24 Apr 2022 21:19:49 +0000 (22:19 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 25 Apr 2022 00:14:28 +0000 (01:14 +0100)
Really we should make this more pervasive, but this is what we need
right now.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/dice.rs
src/utils.rs

index 687283e06f650d395f8d3b8377540096f2dc81ea..3f47b79ab071b400a7b4da9d7a1535299b121630 100644 (file)
@@ -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 {
index 79cc592bb62749e8c698e57232770e768941a6d6..8fb3705ad8a1d462e690ae8ea404b404eeae86c4 100644 (file)
@@ -492,7 +492,7 @@ pub struct FutureInstant(pub Instant);
 
 impl Into<Duration> 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<Duration> 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()
   }
 }