1use std::fmt::Display;
2
3use crate::Timestamp;
4
5impl Display for Timestamp {
6 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7 match f.precision() {
8 Some(p) => {
9 let float = self.seconds as f64 + self.nanos as f64 / 1_000_000_000.0;
10 write!(f, "{:.*}", p, float)
11 },
12 None => write!(f, "{}", self.seconds),
13 }
14 }
15}
16
17#[cfg(test)]
18mod tests {
19 use super::*;
20
21 #[test]
22 fn test_display() {
23 let t = Timestamp::from(1335020400);
24 assert_eq!(format!("{:.02}", t), "1335020400.00");
25 }
26}