-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add utilities to deal with time and duration #103
Conversation
Signed-off-by: Michel Hidalgo <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM -- just left a minor comment
Signed-off-by: Michel Hidalgo <[email protected]>
def as_proper_duration(duration: Union[int, float, timedelta, Duration]) -> Duration: | ||
"""Return `duration` as a proper Duration object. | ||
|
||
Note that for scalar durations the convention is that floating point durations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to add a proper docstring with input specification including units?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm not exactly sure what you mean by input specification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant, something like the following:
Note that for scalar durations the convention is that floating point durations | |
""" | |
Convert various duration inputs into a standardized Duration object. | |
Parameters: | |
duration (Union[int, float, timedelta, Duration]): The duration to be converted. | |
- If an int is provided, it is assumed to be the duration in seconds. | |
- If a float is provided, it is assumed to be the duration in seconds. | |
- If a timedelta is provided, it is converted to the appropriate Duration object. | |
- If a Duration object is provided, it is returned as is. | |
Returns: | |
Duration: A standardized Duration object representing the input duration. | |
Raises: | |
ValueError: If the input duration is not of a supported type. | |
Example: | |
>>> as_proper_duration(3600) | |
<Duration: 3600 seconds> | |
>>> as_proper_duration(2.5) | |
<Duration: 2.5 seconds> | |
>>> as_proper_duration(timedelta(hours=1)) | |
<Duration: 3600 seconds> | |
>>> as_proper_duration(Duration(3600)) | |
<Duration: 3600 seconds> | |
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha! The first example is wrong. Katie's right. The current behavior is going to be confusing. I'll standardize to SI units and include this docstring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See c3262c8. I purposely opted out from duplicating type annotations in docstrings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a minor comment, but looks nice.
Signed-off-by: Michel Hidalgo <[email protected]>
It looks like #96 wasn't enough. The log forwarding test keeps flaking -.- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the comments!
Success! |
Precisely what the title says. Use of Time and Duration representations in Python,
rclpy
,rosbag2
, and our own codebase is not particularly homogeneous. This patch introduces minimal conventions to simplify API implementation.