diff --git a/src/main.rs b/src/main.rs index 81c42ec..93a3765 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,18 +84,14 @@ impl Storage { fn from(&self, t: SystemTime) -> Storage { let mut result = Storage{xs: vec![]}; self.xs.iter() - .filter(|x| !x.clone().clone().before(t)) + .filter(|x| x.ts() >= t) .for_each(|x| result.xs.push(x.clone())); result } } impl X { - fn before(self, t: SystemTime) -> bool { - self.ts() < t - } - - fn ts(self) -> SystemTime { + fn ts(&self) -> SystemTime { UNIX_EPOCH.add(Duration::from_secs(self.t.try_into().unwrap())) } } @@ -109,11 +105,13 @@ mod test_storage { let given = Storage{xs: vec![ X{t: 1, x: "def".to_string(), tag: "abc".to_string()}, X{t: 2, x: "ghi".to_string(), tag: "".to_string()}, + X{t: 3, x: "jkl".to_string(), tag: "".to_string()}, ]}; let want = Storage{xs: vec![ X{t: 2, x: "ghi".to_string(), tag: "".to_string()}, + X{t: 3, x: "jkl".to_string(), tag: "".to_string()}, ]}; - let got = given.from(UNIX_EPOCH.add(Duration::from_secs(1))); + let got = given.from(UNIX_EPOCH.add(Duration::from_secs(2))); assert_eq!(got, want); } }