X-Git-Url: https://git.liburcu.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Ftime.cpp;h=a60fcf23cfabf4c53edc3085084ca88a77996c76;hp=7149912468d2c9d7a6acd41d41e13fe9eed92e90;hb=332a2147fece4548eac38a0929b208230a8da31f;hpb=05aa7e19ec97871aad18d7c9787c4c89611cd2cd diff --git a/src/common/time.cpp b/src/common/time.cpp index 714991246..a60fcf23c 100644 --- a/src/common/time.cpp +++ b/src/common/time.cpp @@ -5,18 +5,19 @@ * */ -#include +#include #include +#include #include -#include -#include -#include -#include +#include + +#include #include -#include #include +#include +#include +#include #include -#include static bool utf8_output_supported; @@ -132,3 +133,18 @@ int time_to_datetime_str(time_t time, char *str, size_t len) end: return ret; } + +std::string lttng::utils::time_to_iso8601_str(std::time_t time) +{ + std::string iso8601_str(ISO8601_STR_LEN, '\0'); + const auto ret = ::time_to_iso8601_str(time, &iso8601_str[0], iso8601_str.capacity()); + + if (ret) { + LTTNG_THROW_ERROR("Failed to format time to iso8601 format"); + } + + /* Don't include '\0' in the C++ string. */ + iso8601_str.resize(iso8601_str.size() - 1); + + return iso8601_str; +}