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

rclcpp::Time::max() clock type support. #2352

Merged
merged 2 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rclcpp/include/rclcpp/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class Time
*/
RCLCPP_PUBLIC
static Time
max();
max(rcl_clock_type_t clock_type = RCL_SYSTEM_TIME); // NOLINT

/// Get the seconds since epoch
/**
Expand Down
4 changes: 2 additions & 2 deletions rclcpp/src/rclcpp/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ Time::operator-=(const rclcpp::Duration & rhs)
}

Time
Time::max()
Time::max(rcl_clock_type_t clock_type)
{
return Time(std::numeric_limits<int32_t>::max(), 999999999);
return Time(std::numeric_limits<int32_t>::max(), 999999999, clock_type);
}


Expand Down
25 changes: 21 additions & 4 deletions rclcpp/test/rclcpp/test_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,27 @@ TEST_F(TestTime, seconds) {
}

TEST_F(TestTime, test_max) {
const rclcpp::Time time_max = rclcpp::Time::max();
const rclcpp::Time max_time(std::numeric_limits<int32_t>::max(), 999999999);
EXPECT_DOUBLE_EQ(max_time.seconds(), time_max.seconds());
EXPECT_EQ(max_time.nanoseconds(), time_max.nanoseconds());
// Same clock types
for (rcl_clock_type_t type = RCL_ROS_TIME;
type != RCL_STEADY_TIME; type = static_cast<rcl_clock_type_t>(type + 1))
{
const rclcpp::Time time_max = rclcpp::Time::max(type);
const rclcpp::Time max_time(std::numeric_limits<int32_t>::max(), 999999999, type);
EXPECT_DOUBLE_EQ(max_time.seconds(), time_max.seconds());
EXPECT_EQ(max_time.nanoseconds(), time_max.nanoseconds());
}
// Different clock types
{
const rclcpp::Time time_max = rclcpp::Time::max(RCL_ROS_TIME);
const rclcpp::Time max_time(std::numeric_limits<int32_t>::max(), 999999999, RCL_STEADY_TIME);
EXPECT_ANY_THROW((void)(time_max == max_time));
EXPECT_ANY_THROW((void)(time_max != max_time));
EXPECT_ANY_THROW((void)(time_max <= max_time));
EXPECT_ANY_THROW((void)(time_max >= max_time));
EXPECT_ANY_THROW((void)(time_max < max_time));
EXPECT_ANY_THROW((void)(time_max > max_time));
EXPECT_ANY_THROW((void)(time_max - max_time));
}
}

TEST_F(TestTime, test_constructor_from_rcl_time_point) {
Expand Down