$darkmode
#include <chrono>#include <string>#include <nlohmann/json.hpp>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) |
| 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:
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.