diff options
Diffstat (limited to 'src/time.rs')
| -rw-r--r-- | src/time.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/time.rs b/src/time.rs index 29206d6..5e82f0c 100644 --- a/src/time.rs +++ b/src/time.rs @@ -203,3 +203,28 @@ mod clock { f } } + +#[cfg(test)] +mod tests { + use super::*; + + // Moved verbatim from tests/time.rs. These two are arithmetic on the + // clock itself and need nothing else; the third test in that file pins a + // lease against a pinned clock, which needs a database, so it stayed. + + #[test] + fn a_pinned_clock_moves_relative_arithmetic_with_it() { + pin("2026-01-01T00:00:00Z"); + assert_eq!(now(), "2026-01-01T00:00:00Z"); + assert_eq!(secs_ahead(90), "2026-01-01T00:01:30Z"); + assert_eq!(secs_ago(90), "2025-12-31T23:58:30Z"); + unpin(); + } + + #[test] + fn an_unpinned_clock_is_the_real_one() { + let n = now(); + assert_eq!(delta_secs(&n, &secs_ahead(60)), Some(60)); + assert_eq!(delta_secs(&n, &secs_ago(60)), Some(-60)); + } +} |
