Skip to content

Commit 76e2b26

Browse files
authored
rclcpp::Time::max() clock type support. (#2352)
Signed-off-by: Tomoya Fujita <[email protected]>
1 parent 5049c45 commit 76e2b26

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

rclcpp/include/rclcpp/time.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class Time
189189
*/
190190
RCLCPP_PUBLIC
191191
static Time
192-
max();
192+
max(rcl_clock_type_t clock_type = RCL_SYSTEM_TIME); // NOLINT
193193

194194
/// Get the seconds since epoch
195195
/**

rclcpp/src/rclcpp/time.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,9 @@ Time::operator-=(const rclcpp::Duration & rhs)
276276
}
277277

278278
Time
279-
Time::max()
279+
Time::max(rcl_clock_type_t clock_type)
280280
{
281-
return Time(std::numeric_limits<int32_t>::max(), 999999999);
281+
return Time(std::numeric_limits<int32_t>::max(), 999999999, clock_type);
282282
}
283283

284284

rclcpp/test/rclcpp/test_time.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,27 @@ TEST_F(TestTime, seconds) {
363363
}
364364

365365
TEST_F(TestTime, test_max) {
366-
const rclcpp::Time time_max = rclcpp::Time::max();
367-
const rclcpp::Time max_time(std::numeric_limits<int32_t>::max(), 999999999);
368-
EXPECT_DOUBLE_EQ(max_time.seconds(), time_max.seconds());
369-
EXPECT_EQ(max_time.nanoseconds(), time_max.nanoseconds());
366+
// Same clock types
367+
for (rcl_clock_type_t type = RCL_ROS_TIME;
368+
type != RCL_STEADY_TIME; type = static_cast<rcl_clock_type_t>(type + 1))
369+
{
370+
const rclcpp::Time time_max = rclcpp::Time::max(type);
371+
const rclcpp::Time max_time(std::numeric_limits<int32_t>::max(), 999999999, type);
372+
EXPECT_DOUBLE_EQ(max_time.seconds(), time_max.seconds());
373+
EXPECT_EQ(max_time.nanoseconds(), time_max.nanoseconds());
374+
}
375+
// Different clock types
376+
{
377+
const rclcpp::Time time_max = rclcpp::Time::max(RCL_ROS_TIME);
378+
const rclcpp::Time max_time(std::numeric_limits<int32_t>::max(), 999999999, RCL_STEADY_TIME);
379+
EXPECT_ANY_THROW((void)(time_max == max_time));
380+
EXPECT_ANY_THROW((void)(time_max != max_time));
381+
EXPECT_ANY_THROW((void)(time_max <= max_time));
382+
EXPECT_ANY_THROW((void)(time_max >= max_time));
383+
EXPECT_ANY_THROW((void)(time_max < max_time));
384+
EXPECT_ANY_THROW((void)(time_max > max_time));
385+
EXPECT_ANY_THROW((void)(time_max - max_time));
386+
}
370387
}
371388

372389
TEST_F(TestTime, test_constructor_from_rcl_time_point) {

0 commit comments

Comments
 (0)