Skip to content

Commit b138ea2

Browse files
committed
Fix MonotonicTime::elapsed()
1 parent 4507d6f commit b138ea2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lightning/src/util/time.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl Time for MonotonicTime {
8989
}
9090

9191
fn elapsed(&self) -> Duration {
92-
self.0.elapsed()
92+
Self::now().0 - self.0
9393
}
9494
}
9595

@@ -180,7 +180,10 @@ pub mod tests {
180180
#[cfg(not(feature = "no-std"))]
181181
fn monotonic_time_go_backward() {
182182
let now = super::MonotonicTime::now();
183+
assert!(now.elapsed() < Duration::from_secs(10));
184+
183185
let ten_years = Duration::from_secs(10 * 365 * 24 * 60 * 60);
184-
let _past = now - ten_years;
186+
let past = now - ten_years;
187+
assert!(past.elapsed() >= ten_years);
185188
}
186189
}

0 commit comments

Comments
 (0)