Implement as_seconds_f32 and as_seconds_f64 for TimeDelta#1671
Implement as_seconds_f32 and as_seconds_f64 for TimeDelta#1671djc merged 2 commits intochronotope:mainfrom
as_seconds_f32 and as_seconds_f64 for TimeDelta#1671Conversation
This makes for more logical grouping of the methods, and opens up a good landing spot for `as_seconds_f32` and `as_seconds`f64` next to `num_seconds`.
25f60c9 to
7f7945e
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1671 +/- ##
==========================================
+ Coverage 91.05% 91.06% +0.01%
==========================================
Files 37 37
Lines 17428 17454 +26
==========================================
+ Hits 15869 15895 +26
Misses 1559 1559 ☔ View full report in Codecov by Sentry. |
|
Who's we/what's your motivation/use case? I think I'd prefer to move towards the core naming, want to rename the other method (retaining a deprecated alias for compatibility)? |
Oh, I just wrote "we" in the PR description out of habit. The motivation is better parity with what
Do you mean rename "num_seconds" to "as_secs"? This seems like a big departure from the current interface, and would make it inconsistent with "num_milliseconds", "num_microseconds", etc. Probably better kept as is for this PR? If you're interested in aligning with In the meantime I'll rename the methods to |
as_seconds_f32 and as_seconds_f64 for TimeDeltaas_secs_f32 and as_secs_f64 for TimeDelta
7f7945e to
9f04a09
Compare
|
Okay, sorry, you've convinced me I was wrong -- let's stick with |
9f04a09 to
ab6c02a
Compare
as_secs_f32 and as_secs_f64 for TimeDeltaas_seconds_f32 and as_seconds_f64 for TimeDelta
Sounds good -- I changed it back to |
ab6c02a to
75826ea
Compare
…conds. Add `as_seconds_f64` and `as_seconds_f32` methods to `TimeDelta` for converting durations to a fractional number of seconds, with single or double precision.
75826ea to
7bac39b
Compare
djc
left a comment
There was a problem hiding this comment.
Thanks!
(In the future, keeping the first line of your commit messages a little shorter would be nice -- typically below 72 chars is best.)
Implement methods for converting a
TimeDeltaobject into a fractional number of seconds, with single or double precision.There are two possible choices for naming these methods:
as_secs_f**oras_seconds_f**. The former is consistent withcore::time::Duration, whereas the latter is consistent with existingTimeDeltamethods (num_seconds, which is calledas_secsincore::time::Duration). Consistency with the existing interface is chosen in this PR.The reverse conversion (from fp seconds to a
TimeDelta) is tricky to get right without unexpected loss of precision, or corner cases causing incorrect rounding or overflow of the number of nanoseconds, so it's not included in this PR.Summary of changes:
subsec_millis,subsec_micros,subsec_nanosnext to their correspondingnum_milliseconds,num_microseconds,num_nanosecondscounterparts, which frees up a good location to addas_secs_f32andadd_secs_f64;as_seconds_f32andas_seconds_f64and associated unit tests.Issue: #1601