diff --git a/src/asciicast.rs b/src/asciicast.rs index b8bb3de..267fafc 100644 --- a/src/asciicast.rs +++ b/src/asciicast.rs @@ -193,10 +193,10 @@ mod tests { assert_eq!(events[0].time, 1); assert!(matches!(events[0].data, EventData::Output(ref s) if s == "ż")); - assert_eq!(events[1].time, 1000000); + assert_eq!(events[1].time, 10000001); assert!(matches!(events[1].data, EventData::Output(ref s) if s == "ółć")); - assert_eq!(events[2].time, 10500000); + assert_eq!(events[2].time, 10500001); assert!(matches!(events[2].data, EventData::Output(ref s) if s == "\r\n")); } diff --git a/src/asciicast/v1.rs b/src/asciicast/v1.rs index 37f1c8d..b6c46ec 100644 --- a/src/asciicast/v1.rs +++ b/src/asciicast/v1.rs @@ -50,12 +50,12 @@ pub fn load(json: String) -> Result> { env: asciicast.env.clone(), }; - let events = Box::new( - asciicast - .stdout - .into_iter() - .map(|e| Ok(Event::output(e.time, e.data))), - ); + let events = Box::new(asciicast.stdout.into_iter().scan(0, |prev_time, event| { + let time = *prev_time + event.time; + *prev_time = time; + + Some(Ok(Event::output(time, event.data))) + })); Ok(Asciicast { header, events }) } diff --git a/tests/casts/full.json b/tests/casts/full.json index 3848391..c27aef6 100644 --- a/tests/casts/full.json +++ b/tests/casts/full.json @@ -15,11 +15,11 @@ "ż" ], [ - 1.000000, + 10.00, "ółć" ], [ - 10.500000, + 0.5, "\r\n" ] ]