time-rs / time

The most used Rust library for date and time handling.
https://time-rs.github.io
Apache License 2.0
1.13k stars 281 forks source link

Port `Duration::from_secs_f32|64` from `std` #576

Closed CryZe closed 1 year ago

CryZe commented 1 year ago

This ports the algorithm for constructing Duration from floating point seconds from std. The new algorithm in std uses bit manipulation to construct the Duration with the most precision possible. Additionally this adds saturating and checked variants of those functions.

Original std PR: https://github.com/rust-lang/rust/pull/90247

codecov[bot] commented 1 year ago

Codecov Report

Merging #576 (d6cdb26) into main (22ae579) will increase coverage by 0.0%. The diff coverage is 100.0%.

@@          Coverage Diff          @@
##            main    #576   +/-   ##
=====================================
  Coverage   95.7%   95.7%           
=====================================
  Files         79      79           
  Lines       8779    8795   +16     
=====================================
+ Hits        8405    8421   +16     
  Misses       374     374           
Impacted Files Coverage Δ
time/src/duration.rs 100.0% <100.0%> (ø)

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

jhpratt commented 1 year ago

Having this code and the code from std side-by-side, I've (unsurprisingly) confirmed that it is the same for everything except where noted. I initially questioned the use of break 'value ..., but then realized the context in quick the macro was being used meant that a simple return would not suffice.

I have no changes to request, so I'm merging it as-is. Thank you for the PR!