mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-30 04:57:54 -06:00
Merge pull request #2467 from Silvertree2010/fix/h2773-seconds-time-display-shows-0-000
Fix "-0.000" in seconds time display for tiny negative times
This commit is contained in:
+14
-1
@@ -389,7 +389,11 @@ pub fn format_time(t: Tick, rate: FrameRate, drop_frame: bool, display: TimeDisp
|
||||
let rem = Tick(abs.rem_euclid(TICKS_PER_SECOND)).to_units_floor(sample_rate);
|
||||
format!("{sign}{:02}:{:02}:{:02}:{rem:05}", secs / 3600, (secs / 60) % 60, secs % 60)
|
||||
}
|
||||
TimeDisplay::Seconds => format!("{:.3}", t.seconds()),
|
||||
TimeDisplay::Seconds => {
|
||||
let s = t.seconds();
|
||||
// A value that rounds to zero must not print a sign ("-0.000").
|
||||
format!("{:.3}", if (s * 1000.0).round() == 0.0 { 0.0 } else { s })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -541,6 +545,15 @@ mod tests {
|
||||
assert!(r.num > 0 && r.den > 0, "got {r:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn seconds_display_has_no_negative_zero() {
|
||||
for t in [Tick(-1), Tick(0), Tick(-100)] {
|
||||
assert_eq!(format_time(t, FrameRate::FPS_30, false, TimeDisplay::Seconds, 48000), "0.000");
|
||||
}
|
||||
let one = Tick(-TICKS_PER_SECOND);
|
||||
assert_eq!(format_time(one, FrameRate::FPS_30, false, TimeDisplay::Seconds, 48000), "-1.000");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn frame_rate_constructors_accept_extreme_numbers() {
|
||||
assert_eq!(FrameRate::new(i64::MIN, 1), FrameRate { num: i64::MIN, den: 1 });
|
||||
|
||||
Reference in New Issue
Block a user