Skip to content

Commit

Permalink
sync branch
Browse files Browse the repository at this point in the history
Signed-off-by: John Shepherd <[email protected]>
  • Loading branch information
John Shepherd committed Sep 2, 2020
2 parents d7c1d31 + f9ef912 commit c5cc779
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
36 changes: 17 additions & 19 deletions include/ignition/math/Helpers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,6 @@ namespace ignition

/// \brief Convert a std::chrono::steady_clock::time_point to a seconds and
/// nanoseconds pair.
/// NOTE: On gcc, system_clock::time_point has nanosecond precision,
// on Windows, it has precision 1/10'000'000 (100ns),
// and on macOS, microsecond precision.
/// \param[in] _time The time point to convert.
/// \return A pair where the first element is the number of seconds and
Expand All @@ -753,8 +751,6 @@ namespace ignition

/// \brief Convert seconds and nanoseconds to
/// std::chrono::steady_clock::time_point.
/// NOTE: On gcc, system_clock::time_point has nanosecond precision,
// on Windows, it has precision 1/10'000'000 (100ns),
// and on macOS, microsecond precision.
/// \param[in] _sec The seconds to convert.
/// \param[in] _nanosec The nanoseconds to convert.
Expand All @@ -773,8 +769,6 @@ namespace ignition

/// \brief Convert a std::chrono::steady_clock::duration to a seconds and
/// nanoseconds pair.
/// NOTE: On gcc, system_clock::time_point has nanosecond precision,
// on Windows, it has precision 1/10'000'000 (100ns),
// and on macOS, microsecond precision.
/// \param[in] _dur The duration to convert.
/// \return A pair where the first element is the number of seconds and
Expand All @@ -792,10 +786,14 @@ namespace ignition
typedef std::chrono::duration<uint64_t, std::ratio<86400>> days;

/// \brief break down durations
/// \param[in] d Duration to breaw down
/// NOTE: the template arguments must be properly ordered according
/// to magnitude and there can be no duplicates.
/// This function uses the braces initializer to split all the templated
/// duration. The initializer will be called recursievely due the `...`
/// \param[in] d Duration to break down
/// \return A tuple based on the durations specified
template<class...Durations, class DurationIn>
std::tuple<Durations...> break_down_durations(DurationIn d) {
std::tuple<Durations...> breakDownDurations(DurationIn d) {
std::tuple<Durations...> retval;
using discard = int[];
(void)discard{0, (void((
Expand All @@ -813,23 +811,23 @@ namespace ignition
const std::chrono::steady_clock::time_point &_point)
{
auto duration = _point - secNsecToTimePoint(0, 0);
auto clean_duration = break_down_durations<days,
std::chrono::hours,
std::chrono::minutes,
std::chrono::seconds,
std::chrono::milliseconds>(
duration);
auto cleanDuration = breakDownDurations<days,
std::chrono::hours,
std::chrono::minutes,
std::chrono::seconds,
std::chrono::milliseconds>(
duration);
std::ostringstream output_string;
output_string << std::setw(2) << std::setfill('0')
<< std::get<0>(clean_duration).count() << " "
<< std::get<0>(cleanDuration).count() << " "
<< std::setw(2) << std::setfill('0')
<< std::get<1>(clean_duration).count() << ":"
<< std::get<1>(cleanDuration).count() << ":"
<< std::setw(2) << std::setfill('0')
<< std::get<2>(clean_duration).count() << ":"
<< std::get<2>(cleanDuration).count() << ":"
<< std::setfill('0') << std::setw(6)
<< std::fixed << std::setprecision(3)
<< std::get<3>(clean_duration).count() +
std::get<4>(clean_duration).count()/1000.0;
<< std::get<3>(cleanDuration).count() +
std::get<4>(cleanDuration).count()/1000.0;
return output_string.str();
}

Expand Down
5 changes: 1 addition & 4 deletions src/Helpers_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,8 @@ TEST(HelpersTest, timePointToSecNsec)
EXPECT_EQ(parts.first, 0);
EXPECT_EQ(parts.second, 0);

using std::chrono::duration_cast;
using std::chrono::nanoseconds;
using std::chrono::steady_clock;
std::chrono::steady_clock::time_point point;
point +=std::chrono::nanoseconds(1000);
point += std::chrono::nanoseconds(1000);
parts = math::timePointToSecNsec(point);

EXPECT_EQ(parts.first, 0);
Expand Down

0 comments on commit c5cc779

Please sign in to comment.