1#define CHRONO_UTILITIES_TIMESPAN_INTEGER_SCALE_OVERLOADS
21#if defined(__GLIBCXX__) && _GLIBCXX_RELEASE < 10
22enum class chars_format { scientific = 1, fixed = 2, hex = 4, general = fixed | scientific };
24using char_format = std::chars_format;
27inline std::from_chars_result from_chars(
const char *first,
const char *last,
double &value, chars_format fmt = chars_format::general)
noexcept
29#if defined(_LIBCPP_VERSION) || (defined(__GLIBCXX__) && _GLIBCXX_RELEASE < 11)
32 auto r = std::from_chars_result{
nullptr, std::errc() };
33 auto s = std::string(first, last);
34 auto l = s.data() + s.size();
35 auto d = std::strtod(s.data(), &l);
36 if (errno == ERANGE) {
37 r.ec = std::errc::result_out_of_range;
38 }
else if (s.data() == l) {
39 r.ec = std::errc::invalid_argument;
42 r.ptr = first + (l - s.data());
46 return std::from_chars(first, last, value, fmt);
80 auto parts = std::array<double, 4>();
81 auto partsPresent = std::size_t();
82 auto specificationsWithUnits =
TimeSpan();
84 for (
const char *
i = str;; ++
i) {
86 if (*
i ==
' ' &&
i == str) {
92 if (*
i != separator && *
i !=
'\0') {
97 if (partsPresent == 4) {
102 auto valuePart = 0.0;
106 const auto res = from_chars(str,
i, valuePart);
107 if (res.ec != std::errc()) {
108 const auto part = std::string_view(str,
static_cast<std::string_view::size_type
>(
i - str));
109 if (res.ec == std::errc::result_out_of_range) {
116 for (
const char *suffix = res.ptr; suffix !=
i; ++suffix) {
117 if (*suffix ==
' ') {
120 if (valueWithUnit.isNull()) {
140 if (*suffix >=
'0' && *suffix <=
'9') {
149 if (valueWithUnit.isNull()) {
150 parts[partsPresent++] = valuePart;
152 specificationsWithUnits += valueWithUnit;
156 if (*
i == separator) {
158 }
else if (*
i ==
'\0') {
164 switch (partsPresent) {
187 stringstream s(stringstream::in | stringstream::out);
191 positive.m_ticks = -positive.m_ticks;
195 s << setfill(
'0') << setw(2) << floor(positive.
totalHours()) <<
":" << setw(2) << positive.
minutes() <<
":" << setw(2) << positive.
seconds();
200 if (milli || micro || nano) {
201 s <<
'.' << setw(3) << milli;
203 s << setw(3) << micro;
219 bool needWhitespace =
false;
220 if (
const int days = positive.
days()) {
221 needWhitespace =
true;
227 needWhitespace =
true;
233 needWhitespace =
true;
239 needWhitespace =
true;
246 needWhitespace =
true;
252 needWhitespace =
true;
266 s << setprecision(0);
268 s << setprecision(10);
#define CPP_UTILITIES_UNUSED(x)
Prevents warnings about unused variables.
The ConversionException class is thrown by the various conversion functions of this library when a co...
Represents a time interval.
constexpr double totalHours() const
Returns the value of the current TimeSpan class expressed in whole and fractional hours.
constexpr double totalSeconds() const
Returns the value of the current TimeSpan class expressed in whole and fractional seconds.
constexpr bool isNull() const
Returns true if the time interval represented by the current TimeSpan class is null.
static constexpr TickType nanosecondsPerTick
constexpr int seconds() const
Returns the seconds component of the time interval represented by the current TimeSpan class.
constexpr int minutes() const
Returns the minutes component of the time interval represented by the current TimeSpan class.
constexpr double totalMicroseconds() const
Returns the value of the current TimeSpan class expressed in whole and fractional microseconds.
constexpr TimeSpan()
Constructs a new instance of the TimeSpan class with zero ticks.
constexpr int days() const
Returns the days component of the time interval represented by the current TimeSpan class.
constexpr int milliseconds() const
Returns the milliseconds component of the time interval represented by the current TimeSpan class.
static constexpr TimeSpan fromDays(double days)
Constructs a new instance of the TimeSpan class with the specified number of days.
static constexpr TimeSpan fromHours(double hours)
Constructs a new instance of the TimeSpan class with the specified number of hours.
static constexpr TimeSpan fromMinutes(double minutes)
Constructs a new instance of the TimeSpan class with the specified number of minutes.
static constexpr TimeSpan fromSeconds(double seconds)
Constructs a new instance of the TimeSpan class with the specified number of seconds.
constexpr int microseconds() const
Returns the microseconds component of the time interval represented by the current TimeSpan class.
std::string toString(TimeSpanOutputFormat format=TimeSpanOutputFormat::Normal, bool fullSeconds=false) const
Converts the value of the current TimeSpan object to its equivalent std::string representation accord...
static TimeSpan fromString(const std::string &str, char separator=':')
Parses the given std::string as TimeSpan.
constexpr double totalMilliseconds() const
Returns the value of the current TimeSpan class expressed in whole and fractional milliseconds.
constexpr bool isNegative() const
Returns true if the time interval represented by the current TimeSpan class is negative.
constexpr int hours() const
Returns the hours component of the time interval represented by the current TimeSpan class.
constexpr int nanoseconds() const
Returns the nanoseconds component of the time interval represented by the current TimeSpan class.
Contains all utilities provides by the c++utilities library.
TimeSpanOutputFormat
Specifies the output format.
StringType argsToString(Args &&...args)