$darkmode
chrono.hpp File Reference
#include <chrono>
#include <string>
#include <nlohmann/json.hpp>
Include dependency graph for chrono.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< std::chrono::duration< Rep, Period > >
 

Functions

std::chrono::nanoseconds fable::parse_duration_to_nanoseconds (const std::string &s)
 
template<typename Duration >
Duration fable::parse_duration (const std::string &s)
 
template<typename Duration >
std::string fable::to_string (const Duration &d)
 
template<>
std::string fable::to_string (const std::chrono::nanoseconds &d)
 

Function Documentation

◆ parse_duration()

template<typename Duration >
Duration fable::parse_duration ( const std::string &  s)

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

The following units are supported:

  • ns | nanosecond | nanoseconds
  • us | microsecond | microseconds
  • ms | millisecond | milliseconds
  • s | second | seconds
  • min | minute | minutes
  • h | hour | hours

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

  • std::invalid_argument if unit missing or unknown
  • std::out_of_range if sub-nanosecond precision used (e.g. 0.5ns)

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 call graph for this function:
Here is the caller graph for this function: