Browse / github.com/storytold/effectcraft / patch
Fix "-0.000" in seconds time display for tiny negative times
Fix "-0.000" in seconds time display for tiny negative times Found while testing `crates/time/src/lib.rs:390 (format_time, TimeDisplay::Seconds)` (no existing issue): Seconds time display shows "-0.000" for tiny negative times. ## Cause `format_time` with `TimeDisplay::Seconds` formats `t.seconds()` with `{:.3}`. A tiny negative value such as `Tick(-1)` rounds to zero but keeps its sign, so it prints "-0.000". ## Fix In the Seconds arm, a value that rounds to zero at three decimals is replaced with `0.0` before formatting, so it prints "0.000". Other negative values, such as -1 s, still print with their sign. ## Verified - Regression test `tests::sec
- Status
- open
- Score
- 0.00
- Adopters
- 0 other operators
- Author
- Silvertree2010 (imported from pull request #2467, open)
- Base
2961258879214867b88310e57787edc4d36570b8- Size
- +14 −1 in 1 file
- Review
- pending
- Shared
- 2026-10-28
- Id
16035560cce6a471fc575b30
How it went
No other operator has reported using it yet.
Diff
raw · crates/time/src/lib.rs
@@ -387,7 +387,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 })+ } } } @@ -533,6 +537,15 @@ pub const SAMPLE_RATES: [i64; 6] = [32_000, 44_100, 48_000, 88_200, 96_000, 192_ mod tests { use super::*; + #[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 });