diff --git a/src/main.rs b/src/main.rs index 2e2c593..720d872 100644 --- a/src/main.rs +++ b/src/main.rs @@ -91,11 +91,12 @@ fn log(f: &String, enabled: &bool, since: &Option) -> Result<(), String> curr.t = x.timestamp(); curr.d = 0.0; } - let d = match curr.xs.len() { - 0 if x.x.len() == 0 => 0.0, - 0 => 1.0, - _ => ((tsheet.xs[i].t - tsheet.xs[i-1].t) as f32 / (60.0*60.0)) as f32, - }; + let mut d = 1.0; + if x.x.len() == 0 { + d = 0.0; + } else if i > 0 { + d = ((tsheet.xs[i].t - tsheet.xs[i-1].t) as f32 / (60.0*60.0)) as f32; + } match x.x.len() { 0 => {}, _ => {