Skip to content

Commit a27b3c8

Browse files
committed
chore: Add tests for humantime formatting
1 parent a93b787 commit a27b3c8

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/fmt/humantime.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,28 @@ impl fmt::Display for Timestamp {
109109
formatter(self.time).fmt(f)
110110
}
111111
}
112+
113+
#[cfg(test)]
114+
mod tests {
115+
use super::Timestamp;
116+
use crate::TimestampPrecision;
117+
118+
#[test]
119+
fn test_display_timestamp() {
120+
let mut ts = Timestamp {
121+
time: std::time::SystemTime::UNIX_EPOCH,
122+
precision: TimestampPrecision::Nanos,
123+
};
124+
125+
assert_eq!("1970-01-01T00:00:00.000000000Z", format!("{ts}"));
126+
127+
ts.precision = TimestampPrecision::Micros;
128+
assert_eq!("1970-01-01T00:00:00.000000Z", format!("{ts}"));
129+
130+
ts.precision = TimestampPrecision::Millis;
131+
assert_eq!("1970-01-01T00:00:00.000Z", format!("{ts}"));
132+
133+
ts.precision = TimestampPrecision::Seconds;
134+
assert_eq!("1970-01-01T00:00:00Z", format!("{ts}"));
135+
}
136+
}

0 commit comments

Comments
 (0)