fix: correct frame rate handling in time calculations

Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
This commit is contained in:
Chaos Rogers 2025-07-31 16:41:17 +01:00
parent 60d57f74d8
commit e805e759c2

View file

@ -39,8 +39,18 @@ pub fn ntp_service_toggle(start: bool) {
pub fn calculate_target_time(frame: &LtcFrame, config: &Config) -> DateTime<Local> {
let today_local = Local::now().date_naive();
let ms = ((frame.frames as f64 / frame.frame_rate) * 1000.0).round() as u32;
let timecode = NaiveTime::from_hms_milli_opt(frame.hours, frame.minutes, frame.seconds, ms)
// Calculate total milliseconds including fractional frames
let total_ms = ((frame.hours as f64 * 3600.0 +
frame.minutes as f64 * 60.0 +
frame.seconds as f64 +
frame.frames as f64 / frame.frame_rate) * 1000.0).round() as u32;
let seconds = total_ms / 1000 % 60;
let minutes = (total_ms / 60000) % 60;
let hours = (total_ms / 3600000) % 24;
let ms_component = total_ms % 1000;
let timecode = NaiveTime::from_hms_milli_opt(hours, minutes, seconds, ms_component)
.expect("Invalid LTC timecode");
let naive_dt = today_local.and_time(timecode);