Skip to content

Commit

Permalink
fix(rust): Fix Display implementation of Duration (#15647)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Apr 15, 2024
1 parent 37c6303 commit 99ab9c0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions crates/polars-time/src/windows/duration.rs
Expand Up @@ -72,8 +72,8 @@ impl Display for Duration {
write!(f, "{}d", self.days)?
}
if self.nsecs > 0 {
let secs = self.nsecs / 1_000_000;
if secs * 1_000_000 == self.nsecs {
let secs = self.nsecs / NANOSECONDS;
if secs * NANOSECONDS == self.nsecs {
write!(f, "{}s", secs)?
} else {
let us = self.nsecs / 1_000;
Expand Down Expand Up @@ -980,4 +980,17 @@ mod test {
one_week_negative.add_ns(t, None).unwrap()
);
}

#[test]
fn test_display() {
let duration = Duration::parse("1h");
let expected = "3600s";
assert_eq!(format!("{duration}"), expected);
let duration = Duration::parse("1h5ns");
let expected = "3600000000005ns";
assert_eq!(format!("{duration}"), expected);
let duration = Duration::parse("1h5000ns");
let expected = "3600000005us";
assert_eq!(format!("{duration}"), expected);
}
}

0 comments on commit 99ab9c0

Please sign in to comment.