FluenTech / embedded-time

Time(ing) library (Instant/Duration/Clock/Timer/Period/Frequency) for bare-metal embedded systems
Apache License 2.0
87 stars 17 forks source link

Fixed bug in Generic<T> comparisons #100

Closed korken89 closed 3 years ago

korken89 commented 3 years ago

Generics do not do comparisons correctly, their fractions are ignored and only the integer parts are compared.

This fixes this issue.

datdenkikniet commented 3 years ago

Thank you for this fix. Hope it gets merged soon!

When using seconds/milliseconds/etc, a workaround exists, as their implementation of PartialOrd and similar do work:

   let milliseconds = Milliseconds(30_000u64);
   duration_ms: Milliseconds<u64> = some_duration.try_into().unwrap();
   // Comparing milliseconds to duration_ms will actually give
   // the expected result, now
PTaylor-us commented 3 years ago

Looks perfect. Thank you!