Skip to content

Commit 202e9b4

Browse files
bors[bot]thvdveld
andauthored
Merge #701
701: Fix how `Instant` is displayed r=thvdveld a=thvdveld Instant was displayed incorrectly. For example, `Instant::from_millis(74)` would have been displayed as "0.74s" instead of the correct "0.074s". bors r+ Co-authored-by: Thibaut Vandervelden <thvdveld@vub.be>
2 parents b66e140 + 09d64b0 commit 202e9b4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/time.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl From<Instant> for ::std::time::SystemTime {
130130

131131
impl fmt::Display for Instant {
132132
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
133-
write!(f, "{}.{}s", self.secs(), self.millis())
133+
write!(f, "{}.{:0>3}s", self.secs(), self.millis())
134134
}
135135
}
136136

@@ -361,8 +361,9 @@ mod test {
361361

362362
#[test]
363363
fn test_instant_display() {
364+
assert_eq!(format!("{}", Instant::from_millis(74)), "0.074s");
364365
assert_eq!(format!("{}", Instant::from_millis(5674)), "5.674s");
365-
assert_eq!(format!("{}", Instant::from_millis(5000)), "5.0s");
366+
assert_eq!(format!("{}", Instant::from_millis(5000)), "5.000s");
366367
}
367368

368369
#[test]

0 commit comments

Comments
 (0)