1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Usages {
usages: Vec<DateTime<Utc>>,
}
impl Usages {
pub fn clear(&mut self) {
self.usages.clear();
}
pub fn list(&self) -> &Vec<DateTime<Utc>> {
&self.usages
}
pub fn new() -> Self {
Self { usages: Vec::new() }
}
pub fn prune(&mut self, before: DateTime<Utc>) {
self.usages.retain(|u| u >= &before);
}
pub fn record_usage(&mut self) {
self.usages.push(Utc::now());
}
}