pub fn next_grid_tick_magnitude_ns(spacing_ns: i64) -> i64 {
if spacing_ns <= 1_000_000_000 {
spacing_ns * 10 } else if spacing_ns == 10_000_000_000 {
spacing_ns * 6 } else if spacing_ns == 60_000_000_000 {
spacing_ns * 10 } else if spacing_ns == 600_000_000_000 {
spacing_ns * 6 } else if spacing_ns == 60 * 60 * 1_000_000_000 {
spacing_ns * 12 } else if spacing_ns == 12 * 60 * 60 * 1_000_000_000 {
spacing_ns * 2 } else {
spacing_ns.checked_mul(10).unwrap_or(spacing_ns) }
}
pub fn format_timestamp_seconds(timestamp_seconds: f64) -> String {
let n = timestamp_seconds as i32;
let hours = n / (60 * 60);
let mins = (n / 60) % 60;
let secs = (n % 60) as f64 + timestamp_seconds.fract();
if hours > 0 {
format!("{hours:02}:{mins:02}:{secs:02.02}")
} else {
format!("{mins:02}:{secs:02.02}")
}
}
pub fn parse_timestamp_seconds(s: &str) -> Option<f64> {
let parts: Vec<&str> = s.split(':').collect();
match parts.len() {
1 => parts[0].parse::<f64>().ok(),
2 => {
let minutes = parts[0].parse::<i32>().ok()?;
let seconds = parts[1].parse::<f64>().ok()?;
Some((minutes * 60) as f64 + seconds)
}
3 => {
let hours = parts[0].parse::<i32>().ok()?;
let minutes = parts[0].parse::<i32>().ok()?;
let seconds = parts[1].parse::<f64>().ok()?;
Some(((hours * 60 + minutes) * 60) as f64 + seconds)
}
_ => None,
}
}