$darkmode
duration.hpp File Reference
#include <chrono>
#include <ratio>
#include <string>
#include <nlohmann/json.hpp>
Include dependency graph for duration.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  nlohmann::adl_serializer< cloe::Microseconds >
 
struct  nlohmann::adl_serializer< cloe::Milliseconds >
 
struct  nlohmann::adl_serializer< cloe::Seconds >
 
struct  nlohmann::adl_serializer< cloe::Duration >
 

Typedefs

using cloe::Microseconds = std::chrono::duration< double, std::micro >
 
using cloe::Milliseconds = std::chrono::duration< double, std::milli >
 
using cloe::Seconds = std::chrono::duration< double >
 

Functions

std::string cloe::to_string (const Duration &ns)
 
Duration cloe::parse_duration (const std::string &fmt)
 
nlohmann::json cloe::to_convenient_json (const Duration &ns)
 
std::string nlohmann::to_string_hr (double d)
 

Detailed Description

See also
cloe/core.hpp

Function Documentation

◆ parse_duration()

Duration cloe::parse_duration ( const std::string &  fmt)

Convert a string containing a number and a unit to a duration.

The following units are supported:

ns
us
ms
s

Will throw an exception on malformed or out-of-range input.

Note: This parse function preserves precision even for floating point numbers. For example, 0.1 is not exactly representable as a floating point number, but together with a unit, we can scale it so that it is represented exactly.

Here is the caller graph for this function: