use num::{traits::Inv, Rational64, Zero};
use crate::{Framerate, FramesSourceResult, TimecodeParseError};
pub(super) fn convert_tc_int(value: &str, section_name: &str) -> FramesSourceResult {
match value.parse::<i64>() {
Ok(parsed) => Ok(parsed),
Err(err) => Err(TimecodeParseError::Conversion(format!(
"error converting {} to i64: {}",
section_name, err,
))),
}
}
pub(crate) fn round_seconds_to_frame(seconds: Rational64, rate: Framerate) -> Rational64 {
if seconds % rate.playback().inv() != Rational64::zero() {
let frames = (seconds * rate.playback()).round();
frames / rate.playback()
} else {
seconds
}
}