forked from ordinals/ord
-
Notifications
You must be signed in to change notification settings - Fork 21
/
blocktime.rs
41 lines (34 loc) Β· 763 Bytes
/
blocktime.rs
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
37
38
39
40
41
use super::*;
#[derive(Copy, Clone)]
pub(crate) enum Blocktime {
Confirmed(i64),
Expected(i64),
}
impl Blocktime {
fn timestamp(self) -> i64 {
match self {
Self::Confirmed(timestamp) | Self::Expected(timestamp) => timestamp,
}
}
}
impl Display for Blocktime {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{}", NaiveDateTime::from_timestamp(self.timestamp(), 0))?;
if let Self::Expected(_) = self {
write!(f, " (expected)")?;
}
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn display() {
assert_eq!(Blocktime::Confirmed(0).to_string(), "1970-01-01 00:00:00");
assert_eq!(
Blocktime::Expected(0).to_string(),
"1970-01-01 00:00:00 (expected)"
);
}
}