Commit 34d4e960 authored by Dominik Charousset's avatar Dominik Charousset

Add convenience functions to timestamp

parent 9a9c7bc6
......@@ -20,8 +20,9 @@
#ifndef CAF_TIMESTAMP_HPP
#define CAF_TIMESTAMP_HPP
#include <cstdint>
#include <chrono>
#include <string>
#include <cstdint>
namespace caf {
......@@ -31,6 +32,16 @@ using timestamp = std::chrono::time_point<
std::chrono::duration<int64_t, std::nano>
>;
/// Convenience function for returning a `timestamp` representing
/// the current system time.
timestamp make_timestamp();
/// Converts the time-since-epoch of `x` to a `string`.
std::string timestamp_to_string(const timestamp& x);
/// Appends the time-since-epoch of `y` to `x`.
void append_timestamp_to_string(std::string& x, const timestamp& y);
} // namespace caf
#endif // CAF_TIMESTAMP_HPP
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2016 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/timestamp.hpp"
namespace caf {
timestamp make_timestamp() {
return std::chrono::system_clock::now();
}
std::string timestamp_to_string(const timestamp& x) {
return std::to_string(x.time_since_epoch().count());
}
void append_timestamp_to_string(std::string& x, const timestamp& y) {
x += std::to_string(y.time_since_epoch().count());
}
} // namespace caf
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment