Function cras::parseTime
Defined in File rclcpp.hpp
Function Documentation
Parse the given string as time.
This function accepts this general format:
However, many modifications of the format are supported:
The delimiter can be any of
:-/_(or empty string) and it doesn’t need to be consistent in the string.The space delimiting date and time can be actually any of
Tt_-.The date part can be omitted. In that case, the date will be taken from
referenceTime.If year is given just as two digits,
20YYis assumed.If time zone offset is not specified in the string, it will be taken from
timezoneOffset. But if the string contains a TZ offset, it will be used instead the one passed as argument. If neither is specified, UTC is assumed.If nonempty delimiters are used, the fields do not need to be zero-padded and can overflow their natural limit up to UINT16_MAX.
A special value
nowis recognized and always returns current time. It can be any case (NOW,Nowetc.).Decimal comma
,can be used instead of decimal dot..
- Parameters:
s – [in] The string to parse.
timezoneOffset – [in] Optional timezone offset to use if no offset is specified in the string.
referenceDate – [in] If the date part is missing in the string, the date from this argument will be used.
clock – [in] The clock to be used in case “now” is passed. Also, the type of the clock defines the type of the result (defaults to RCL_SYSTEM_TIME if this clock is nullptr). If the clock is null, current system clock will be used.
- Throws:
std::invalid_argument – If the string does not represent a date with time.
- Returns:
The parsed time as seconds from epoch.