2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2018-10-08 11:56:40 +00:00
|
|
|
|
2023-10-24 13:18:03 +00:00
|
|
|
#include "types.hpp"
|
|
|
|
|
2022-07-16 00:41:14 +00:00
|
|
|
#include <fmt/chrono.h>
|
2023-10-24 13:18:03 +00:00
|
|
|
#include <fmt/format.h>
|
|
|
|
#include <nlohmann/json.hpp>
|
2023-10-19 21:59:57 +00:00
|
|
|
|
2023-10-24 13:18:03 +00:00
|
|
|
#include <iostream>
|
2018-11-19 22:45:37 +00:00
|
|
|
|
2020-02-24 19:40:45 +00:00
|
|
|
using namespace std::chrono_literals;
|
2020-01-30 22:10:56 +00:00
|
|
|
|
2018-10-08 11:56:40 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
2023-11-28 12:55:01 +00:00
|
|
|
using rc_time = std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds>;
|
|
|
|
|
|
|
|
rc_time
|
|
|
|
time_point_now();
|
|
|
|
|
2020-01-23 14:41:33 +00:00
|
|
|
/// get time right now as milliseconds, this is monotonic
|
2021-04-02 15:10:37 +00:00
|
|
|
Duration_t
|
2018-11-19 22:45:37 +00:00
|
|
|
time_now_ms();
|
2020-02-25 17:05:13 +00:00
|
|
|
|
2021-04-02 15:10:37 +00:00
|
|
|
/// get the uptime of the process
|
|
|
|
Duration_t
|
|
|
|
uptime();
|
|
|
|
|
|
|
|
/// convert to milliseconds
|
|
|
|
uint64_t
|
|
|
|
ToMS(Duration_t duration);
|
|
|
|
|
2020-02-25 17:05:13 +00:00
|
|
|
nlohmann::json
|
2021-04-02 15:10:37 +00:00
|
|
|
to_json(const Duration_t& t);
|
2020-01-30 22:10:56 +00:00
|
|
|
|
2022-10-27 00:20:14 +00:00
|
|
|
// Returns a string such as "27m13s ago" or "in 1h12m" or "now". You get precision of minutes
|
|
|
|
// (for >=1h), seconds (>=10s), or milliseconds. The `now_threshold` argument controls how close
|
|
|
|
// to current time (default 1s) the time has to be to get the "now" argument.
|
|
|
|
std::string
|
|
|
|
short_time_from_now(const TimePoint_t& t, const Duration_t& now_threshold = 1s);
|
2022-05-20 15:11:34 +00:00
|
|
|
|
2022-10-27 00:20:14 +00:00
|
|
|
// Makes a duration human readable. This always has full millisecond precision, but formats up to
|
|
|
|
// hours. E.g. "-4h04m12.123s" or "1234h00m09.876s.
|
|
|
|
std::string
|
|
|
|
ToString(Duration_t t);
|
2022-05-20 15:11:34 +00:00
|
|
|
|
2022-10-27 00:20:14 +00:00
|
|
|
} // namespace llarp
|
2022-05-20 15:11:34 +00:00
|
|
|
|
2022-10-27 00:20:14 +00:00
|
|
|
// Duration_t is currently just a typedef to std::chrono::milliseconds, and specializing
|
|
|
|
// that seems wrong; leaving this here to remind us not to add it back in again.
|
|
|
|
// namespace fmt
|
|
|
|
//{
|
|
|
|
// template <>
|
|
|
|
// struct formatter<llarp::Duration_t>
|
|
|
|
// {
|
|
|
|
// };
|
|
|
|
//} // namespace fmt
|