Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functions to convert between time_point and secNsec #150

Merged
merged 18 commits into from
Sep 3, 2020

Conversation

ahcorde
Copy link
Contributor

@ahcorde ahcorde commented Aug 26, 2020

This PR is related with this issue gazebosim/gz-common#61. The idea it's to deprecate the class common::Time in favor of std::chrono.

Related with

Added helpers fucntions to converte between

  • sec and nanosec to time_point
  • time_point to sec and nanosec
  • some tests too

Signed-off-by: ahcorde [email protected]

@ahcorde
Copy link
Contributor Author

ahcorde commented Aug 26, 2020

I added this function to convert a time_point to string. is this the right place? 489a79e

include/ignition/math/Helpers.hh Outdated Show resolved Hide resolved
include/ignition/math/Helpers.hh Outdated Show resolved Hide resolved
@ahcorde ahcorde requested a review from scpeters August 26, 2020 16:13
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
@JShep1 JShep1 self-requested a review August 27, 2020 01:22
Signed-off-by: ahcorde <[email protected]>
@codecov
Copy link

codecov bot commented Aug 27, 2020

Codecov Report

Merging #150 into ign-math6 will decrease coverage by 0.01%.
The diff coverage is 97.14%.

Impacted file tree graph

@@              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     
Impacted Files Coverage Δ
include/ignition/math/Helpers.hh 99.13% <97.14%> (-0.87%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9ff0f1c...f9ef912. Read the comment docs.

@JShep1
Copy link

JShep1 commented Aug 27, 2020

Do you think it would be appropriate to also place a std::string (in format dd hh:mm:ss.nnn) to std::chrono::time_point helper function in here? I'm currently working on one for a gazebo gui plugin and thought it might be helpful to add it to a more global location. If we want to do this, I can create a separate PR. @scpeters @ahcorde

@JShep1
Copy link

JShep1 commented Aug 28, 2020

Do you think it would be appropriate to also place a std::string (in format dd hh:mm:ss.nnn) to std::chrono::time_point helper function in here? I'm currently working on one for a gazebo gui plugin and thought it might be helpful to add it to a more global location. If we want to do this, I can create a separate PR. @scpeters @ahcorde

See #152

Copy link

@JShep1 JShep1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Show resolved Hide resolved
include/ignition/math/Helpers.hh Outdated Show resolved Hide resolved
include/ignition/math/Helpers.hh Show resolved Hide resolved
include/ignition/math/Helpers.hh Outdated Show resolved Hide resolved
include/ignition/math/Helpers.hh Outdated Show resolved Hide resolved
_nanosec);
std::chrono::system_clock::time_point result =
std::chrono::system_clock::from_time_t(0);
result = result + duration;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

include/ignition/math/Helpers.hh Outdated Show resolved Hide resolved
Cast to system_clock::duration where necessary.

Signed-off-by: Steve Peters <[email protected]>
@scpeters
Copy link
Member

I've fixed compilation on macOS in f11f678, though there is a test failure; I'll comment on the specific line

parts = math::timePointToSecNsec(point);

EXPECT_EQ(parts.first, 60);
EXPECT_EQ(parts.second, 5789);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, I should have read @JShep1's comment first: #150 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we should expect duration_cast<system_clock::duration>(5789)?

@ahcorde
Copy link
Contributor Author

ahcorde commented Aug 31, 2020

ŧhank you @scpeters for the fix and @JShep1 for the pointer to the precision.

Copy link
Contributor

@mjcarroll mjcarroll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be using steady_clock instead?

include/ignition/math/Helpers.hh Outdated Show resolved Hide resolved
Copy link

@JShep1 JShep1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than some documentation updates

include/ignition/math/Helpers.hh Outdated Show resolved Hide resolved
include/ignition/math/Helpers.hh Outdated Show resolved Hide resolved
include/ignition/math/Helpers.hh Outdated Show resolved Hide resolved
src/Helpers_TEST.cc Outdated Show resolved Hide resolved
include/ignition/math/Helpers.hh Outdated Show resolved Hide resolved
include/ignition/math/Helpers.hh Outdated Show resolved Hide resolved
src/Helpers_TEST.cc Outdated Show resolved Hide resolved
Signed-off-by: ahcorde <[email protected]>
@@ -23,6 +23,8 @@
#include <limits>
#include <string>
#include <iostream>
#include <sstream>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're in here, can we alphabetize includes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done :) f9ef912

@ahcorde ahcorde merged commit d5dc70f into ign-math6 Sep 3, 2020
@ahcorde ahcorde deleted the ahcorde/time/helper_functions branch September 3, 2020 07:47
ahcorde added a commit that referenced this pull request Sep 3, 2020
* Added functions to convert between time_point and secNsec

Signed-off-by: ahcorde <[email protected]>

* Add function to convert a time_point in a string

Signed-off-by: ahcorde <[email protected]>

* Simplify math in timepoint convertions

Signed-off-by: ahcorde <[email protected]>

* make linters happy

Signed-off-by: ahcorde <[email protected]>

* make linters happy

Signed-off-by: ahcorde <[email protected]>

* make linters happy

Signed-off-by: ahcorde <[email protected]>

* Fixed test

Signed-off-by: ahcorde <[email protected]>

* Added test for timePointToString

Signed-off-by: ahcorde <[email protected]>

* Added documentation feedback

Signed-off-by: ahcorde <[email protected]>

* Fix macOS build

Cast to system_clock::duration where necessary.

Signed-off-by: Steve Peters <[email protected]>

* Fixed test and added a note with the precision on different OS

Signed-off-by: ahcorde <[email protected]>

* Change std::chrono::system_clock for std::chrono::steady_clock

Signed-off-by: ahcorde <[email protected]>

* Removed comment

Signed-off-by: ahcorde <[email protected]>

* Added feedback

Signed-off-by: ahcorde <[email protected]>

* alphabetize headers in helpers.hh

Signed-off-by: ahcorde <[email protected]>

Co-authored-by: John Shepherd <[email protected]>
Co-authored-by: Steve Peters <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📜 blueprint Ignition Blueprint 🏰 citadel Ignition Citadel 🔮 dome Ignition Dome enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants