Fix time conversion to ms
Signed-off-by: Andreas Rauschert andreas.rb.rauschert@bmw.de
Merge request reports
Activity
requested review from @jtschea and @ckochendoerfer
26 26 /// @return Duration representing the given input in units of @ref Time. 27 27 inline Time SecondsToTime(double duration) 28 28 { 29 return units::time::second_t(duration); 29 return {std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::duration<double>{duration})}; Good idea! I tested it with int64_t and in general it works. The impacts are:
- the SecondsToTime(double) also needs to be adjusted to first convert to unit::milliseconds_t (double) and then to Time (int), otherwise the ms are cut off during the cast. This means you must not/cannot cast yourself anymore from units::seconds_t to Time
- you cannot do calculations with the default units time types anymore without casting (so e.g. my_mantle_time + 10_ms) doesn't work since the types are different. You have to write (my_mantle_time + mantle_api::Time{10})
What is your preference?
Edited by Andreas RauschertI am still a bit undecieded. With the second point I don't see any issues. The places which currently already require milliseconds as integer need a conversion anyway. In the modules where we do actual calculations they completly run in doubles and could still use the units literals.
The only thing that worries me with the first point is, that users might assume that the conversion from units::seconds_t to Time to works implicitly. Since this doesn't throw any compile errors, those mistakes could be hard to find.
Edited by Christoph KochendoerferI still lack experience with the units extension. To make a final decision it probably requires some more experimenting. In order to move forward, I would be fine with both solutions at the moment.
I would prefer to stick closer to the units, but this could lead to missuse and hardtofind errors at the moment.
Should we discuss it in our meeting tomorrow?
changed this line in version 2 of the diff
Yes, let's discuss. I just made one last change for our backward compatibility and made the secondstotime a template again. This fixes the behaviour for floats as input.
@ckochendoerfer Can you please approve again? Since Jupp is already on leave but approved before guess he would be alright with templating the function, so we can proceed.Edited by Andreas Rauschert
mentioned in commit 840c01ab