time_utils.h 1.41 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*******************************************************************************
 * Copyright (c) 2021, Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *******************************************************************************/

//-----------------------------------------------------------------------------
/** @file  time_utils.h */
//-----------------------------------------------------------------------------

#ifndef MANTLEAPI_COMMON_TIME_UTILS_H
#define MANTLEAPI_COMMON_TIME_UTILS_H

#include <units.h>

namespace mantle_api
{
using Time = units::time::millisecond_t;

/// @brief Converts input in [s] to @ref Time.
/// @tparam T Input type, eg. `double`.
/// @param duration Input value
/// @return Duration representing the given input in units of @ref Time.
template <typename T>
inline Time SecondsToTime(T duration)
{
31
    return units::convert<units::time::seconds, Time>(duration);
32
33
34
35
36
37
38
39
40
41
42
43
44
}

/// @brief Converts input @ref Time to [s].
/// @param time Time
/// @return Duration in seconds representing the passed in @ref Time.
inline double TimeToSeconds(const Time& time)
{
    return units::time::second_t{time}.value();
}

}  // namespace mantle_api

#endif  // MANTLEAPI_COMMON_TIME_UTILS_H