diff --git a/rclcpp/include/rclcpp/time.hpp b/rclcpp/include/rclcpp/time.hpp index 15533f39ef..b6aee4c972 100644 --- a/rclcpp/include/rclcpp/time.hpp +++ b/rclcpp/include/rclcpp/time.hpp @@ -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 /** diff --git a/rclcpp/src/rclcpp/time.cpp b/rclcpp/src/rclcpp/time.cpp index 556a5e69ad..e5ff2af8d0 100644 --- a/rclcpp/src/rclcpp/time.cpp +++ b/rclcpp/src/rclcpp/time.cpp @@ -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::max(), 999999999); + return Time(std::numeric_limits::max(), 999999999, clock_type); } diff --git a/rclcpp/test/rclcpp/test_time.cpp b/rclcpp/test/rclcpp/test_time.cpp index f3969d3886..7d656fb9c4 100644 --- a/rclcpp/test/rclcpp/test_time.cpp +++ b/rclcpp/test/rclcpp/test_time.cpp @@ -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::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(type + 1)) + { + const rclcpp::Time time_max = rclcpp::Time::max(type); + const rclcpp::Time max_time(std::numeric_limits::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::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) {