Skip to content

Conversation

@mabushey
Copy link

@mabushey mabushey commented Mar 1, 2022

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!

@kaegi
Copy link
Owner

kaegi commented Mar 1, 2022

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.

@mabushey
Copy link
Author

mabushey commented Mar 1, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants