Added functions to convert between time_point and secNsec#150
Added functions to convert between time_point and secNsec#150
Conversation
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
|
I added this function to convert a time_point to string. is this the right place? 489a79e |
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
Codecov Report
@@ Coverage Diff @@
## ign-math6 #150 +/- ##
=============================================
- Coverage 99.25% 99.24% -0.02%
=============================================
Files 59 59
Lines 5788 5823 +35
=============================================
+ Hits 5745 5779 +34
- Misses 43 44 +1
Continue to review full report at Codecov.
|
Signed-off-by: ahcorde <ahcorde@gmail.com>
|
Do you think it would be appropriate to also place a |
See #152 |
There was a problem hiding this comment.
Looks (and works) great! I'm currently using these helper functions in this plugin and it's quite handy. Some small nits with documentation and such but other than that I think it should be ready to go.
include/ignition/math/Helpers.hh
Outdated
| _nanosec); | ||
| std::chrono::system_clock::time_point result = | ||
| std::chrono::system_clock::from_time_t(0); | ||
| result = result + duration; |
There was a problem hiding this comment.
Small nit: could condense with result += duration, I'll leave it up to you though, same with all below additions like this made in the tests
There was a problem hiding this comment.
This line is failing in OSX https://build.osrfoundation.org/job/ignition_math-ci-pr_any-homebrew-amd64/666/consoleFull#1943795879aa60f765-a60a-427d-900c-dc128ab22287 even if you use your suggestion. Any thoughts?
There was a problem hiding this comment.
sorry for making suggestions that don't actually work; I thought it would be cleaner. I'll take a look with my mac later today
There was a problem hiding this comment.
I looked into this a bit: Seems like OSX stores chrono to only a microsecond precision, whereas Ubuntu goes to nanosecond precision. It seems like all platforms have different precisions. See eddelbuettel/nanotime#74 and https://stackoverflow.com/questions/55120594/different-behaviour-of-system-clock-on-windows-and-linux
Signed-off-by: ahcorde <ahcorde@gmail.com>
…nitionrobotics/ign-math into ahcorde/time/helper_functions
Cast to system_clock::duration where necessary. Signed-off-by: Steve Peters <scpeters@openrobotics.org>
|
I've fixed compilation on macOS in f11f678, though there is a test failure; I'll comment on the specific line |
src/Helpers_TEST.cc
Outdated
| parts = math::timePointToSecNsec(point); | ||
|
|
||
| EXPECT_EQ(parts.first, 60); | ||
| EXPECT_EQ(parts.second, 5789); |
There was a problem hiding this comment.
this expectation is failing on macOS, it gets 5000 instead of 5789. My guess is that the system_clock::duration cast in line 542 is changing the time base to microseconds, presumably because that's the resolution of the system clock?
I'm not sure what the best way to account for that is
There was a problem hiding this comment.
oops, I should have read @JShep1's comment first: #150 (comment)
There was a problem hiding this comment.
perhaps we should expect duration_cast<system_clock::duration>(5789)?
Signed-off-by: ahcorde <ahcorde@gmail.com>
…nitionrobotics/ign-math into ahcorde/time/helper_functions
mjcarroll
left a comment
There was a problem hiding this comment.
Should we be using steady_clock instead?
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
| #include <limits> | ||
| #include <string> | ||
| #include <iostream> | ||
| #include <sstream> |
There was a problem hiding this comment.
While we're in here, can we alphabetize includes?
Signed-off-by: ahcorde <ahcorde@gmail.com>
* Added functions to convert between time_point and secNsec Signed-off-by: ahcorde <ahcorde@gmail.com> * Add function to convert a time_point in a string Signed-off-by: ahcorde <ahcorde@gmail.com> * Simplify math in timepoint convertions Signed-off-by: ahcorde <ahcorde@gmail.com> * make linters happy Signed-off-by: ahcorde <ahcorde@gmail.com> * make linters happy Signed-off-by: ahcorde <ahcorde@gmail.com> * make linters happy Signed-off-by: ahcorde <ahcorde@gmail.com> * Fixed test Signed-off-by: ahcorde <ahcorde@gmail.com> * Added test for timePointToString Signed-off-by: ahcorde <ahcorde@gmail.com> * Added documentation feedback Signed-off-by: ahcorde <ahcorde@gmail.com> * Fix macOS build Cast to system_clock::duration where necessary. Signed-off-by: Steve Peters <scpeters@openrobotics.org> * Fixed test and added a note with the precision on different OS Signed-off-by: ahcorde <ahcorde@gmail.com> * Change std::chrono::system_clock for std::chrono::steady_clock Signed-off-by: ahcorde <ahcorde@gmail.com> * Removed comment Signed-off-by: ahcorde <ahcorde@gmail.com> * Added feedback Signed-off-by: ahcorde <ahcorde@gmail.com> * alphabetize headers in helpers.hh Signed-off-by: ahcorde <ahcorde@gmail.com> Co-authored-by: John Shepherd <john@openrobotics.org> Co-authored-by: Steve Peters <scpeters@openrobotics.org>
This PR is related with this issue gazebosim/gz-common#61. The idea it's to deprecate the class
common::Timein favor ofstd::chrono.Related with
Added helpers fucntions to converte between
Signed-off-by: ahcorde ahcorde@gmail.com