mirror of
https://github.com/storytold/filmcraft.git
synced 2026-10-24 10:10:05 -06:00
Fix AudioSamples time display for negative times
Found while testing crates/time/src/lib.rs:418 (format_time, TimeDisplay::AudioSamples) Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
6c3948a36c
commit
9a93d175a4
+14
-3
@@ -416,9 +416,12 @@ pub fn format_time(t: Tick, rate: FrameRate, drop_frame: bool, display: TimeDisp
|
||||
format!("{}{}+{:02}", if neg { "-" } else { "" }, a / per_ft, a % per_ft)
|
||||
}
|
||||
TimeDisplay::AudioSamples => {
|
||||
let secs = t.0.div_euclid(TICKS_PER_SECOND);
|
||||
let rem = Tick(t.0.rem_euclid(TICKS_PER_SECOND)).to_units_floor(sample_rate);
|
||||
format!("{:02}:{:02}:{:02}:{rem:05}", secs / 3600, (secs / 60) % 60, secs % 60)
|
||||
let neg = t.0 < 0;
|
||||
let a = t.0.unsigned_abs();
|
||||
let tps = TICKS_PER_SECOND.unsigned_abs();
|
||||
let secs = a / tps;
|
||||
let rem = Tick((a % tps) as i64).to_units_floor(sample_rate);
|
||||
format!("{}{:02}:{:02}:{:02}:{rem:05}", if neg { "-" } else { "" }, secs / 3600, (secs / 60) % 60, secs % 60)
|
||||
}
|
||||
TimeDisplay::Seconds => format!("{:.3}", t.seconds()),
|
||||
}
|
||||
@@ -507,6 +510,14 @@ mod tests {
|
||||
use super::*;
|
||||
use proptest::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn audio_samples_negative_time_has_leading_minus() {
|
||||
let r = FrameRate::new(30000, 1001);
|
||||
let f = |t| format_time(Tick(t), r, false, TimeDisplay::AudioSamples, 48000);
|
||||
assert_eq!(f(-TICKS_PER_SECOND), "-00:00:01:00000");
|
||||
assert_eq!(f(-(TICKS_PER_SECOND + TICKS_PER_SECOND / 2)), "-00:00:01:24000");
|
||||
}
|
||||
|
||||
/// Damaged files and projects can carry zero / negative rates and timebases, and users or
|
||||
/// agents can type huge timecodes: these used to panic (division by zero, overflow,
|
||||
/// crossed `clamp` bounds).
|
||||
|
||||
Reference in New Issue
Block a user