Skip to content

Commit

Permalink
Add TIME_MAX and DURATION_MAX functions (#538)
Browse files Browse the repository at this point in the history
* Add TIME_MAX and DURATION_MAX functions

* Fix Linting Errors

* change funtion name as per coding style

* change function name as per coding style

* Update duration.cpp

* Update time.cpp

* Update test_duration.cpp

* Update time.hpp

* remove extra empty line
  • Loading branch information
sagniknitr authored and dirk-thomas committed Aug 27, 2018
1 parent 354d933 commit 18ad26e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rclcpp/include/rclcpp/duration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class Duration
Duration
operator-(const rclcpp::Duration & rhs) const;

RCLCPP_PUBLIC
static Duration
max();

RCLCPP_PUBLIC
Duration
operator*(double scale) const;
Expand Down
4 changes: 4 additions & 0 deletions rclcpp/include/rclcpp/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ class Time
rcl_time_point_value_t
nanoseconds() const;

RCLCPP_PUBLIC
static Time
max();

/// \return the seconds since epoch as a floating point number.
/// \warning Depending on sizeof(double) there could be significant precision loss.
/// When an exact time is required use nanoseconds() instead.
Expand Down
6 changes: 6 additions & 0 deletions rclcpp/src/rclcpp/duration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ Duration::nanoseconds() const
return rcl_duration_.nanoseconds;
}

Duration
Duration::max()
{
return Duration(std::numeric_limits<int32_t>::max(), 999999999);
}

double
Duration::seconds() const
{
Expand Down
6 changes: 6 additions & 0 deletions rclcpp/src/rclcpp/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,11 @@ operator+(const rclcpp::Duration & lhs, const rclcpp::Time & rhs)
return Time(lhs.nanoseconds() + rhs.nanoseconds(), rhs.get_clock_type());
}

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


} // namespace rclcpp
7 changes: 7 additions & 0 deletions rclcpp/test/test_duration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,10 @@ TEST(TestDuration, negative_duration) {
EXPECT_EQ(expected_value, assignable_duration.nanoseconds());
}
}

TEST(TestDuration, maximum_duration) {
rclcpp::Duration max_duration = rclcpp::Duration::max();
rclcpp::Duration max(std::numeric_limits<int32_t>::max(), 999999999);

EXPECT_EQ(max_duration, max);
}

0 comments on commit 18ad26e

Please sign in to comment.