subparse
subparse copied to clipboard
Add missing Timepoint Add (Sub exists)
Sub for TimePoint exists, but not Add:
49 | let t2 = subtitle_entries[pos+3].timespan.end + TimePoint::from_secs(2);
| ^^^^^^^^^^^^^^^^^^^^^^^ expected struct `TimeDelta`, found struct `TimePoint`
However we have impl Sub<TimeDelta> for TimePoint
, so this works to add:
let t2 = subtitle_entries[pos+3].timespan.end - TimePoint::from_secs(-2);
This PR adds the Add for TimePoint, so now there is both add and sub.
The crate is awesome, thanks!
A TimePoint is the equivalent to an "Instant" in std, TimeDelta to "Duration". You can not add the TimePoints or dates "next Tuesday" and "next Friday", but you can add or subtract a TimeDelta of "3 days".
"TimePoint minus TimePoint" is a TimeDelta. So "Monday + (Friday - Thursday) = Monday + 1day = Tuesday".
The idea behind this separation was to forbid the addition of TimePoints to avoid implementation mistakes. It might be a little bit overengineered :) Try using a TimeDelta for your application and see how it goes.
I just copied the missing Add so we have Add and Sub. Right now I'm Subtracting a negative so it's working for my use but klunky. I'm making a short preview video with the subtitles baked in to test that the subtitles are aligned correct:
let t1 = subtitle_entries[pos].timespan.start - TimePoint::from_secs(2);
let t2 = subtitle_entries[pos+3].timespan.end - TimePoint::from_secs(-2);
I'm quite new to rust so please let me know if there's a better way.