1#define CHRONO_UTILITIES_TIMESPAN_INTEGER_SCALE_OVERLOADS
20#if defined(__GLIBCXX__) && _GLIBCXX_RELEASE < 10
21enum class chars_format { scientific = 1, fixed = 2, hex = 4, general = fixed | scientific };
23using char_format = std::chars_format;
26inline std::from_chars_result from_chars(
const char *first,
const char *last,
double &value, chars_format fmt = chars_format::general)
noexcept
28#if defined(_LIBCPP_VERSION) || (defined(__GLIBCXX__) && _GLIBCXX_RELEASE < 11)
31 auto r = std::from_chars_result{
nullptr, std::errc() };
32 auto s = std::string(first, last);
33 auto l = s.data() + s.size();
34 auto d = std::strtod(s.data(), &l);
35 if (errno == ERANGE) {
36 r.ec = std::errc::result_out_of_range;
37 }
else if (s.data() == l) {
38 r.ec = std::errc::invalid_argument;
41 r.ptr = first + (l - s.data());
45 return std::from_chars(first, last, value, fmt);
79 auto parts = std::array<double, 4>();
80 auto partsPresent = std::size_t();
81 auto specificationsWithUnits =
TimeSpan();
83 for (
const char *
i = str;; ++
i) {
85 if (*
i ==
' ' &&
i == str) {
91 if (*
i != separator && *
i !=
'\0') {
96 if (partsPresent == 4) {
101 auto valuePart = 0.0;
105 const auto res = from_chars(str,
i, valuePart);
106 if (res.ec != std::errc()) {
107 const auto part = std::string_view(str,
static_cast<std::string_view::size_type
>(
i - str));
108 if (res.ec == std::errc::result_out_of_range) {
115 for (
const char *suffix = res.ptr; suffix !=
i; ++suffix) {
116 if (*suffix ==
' ') {
119 if (valueWithUnit.isNull()) {
139 if (*suffix >=
'0' && *suffix <=
'9') {
148 if (valueWithUnit.isNull()) {
149 parts[partsPresent++] = valuePart;
151 specificationsWithUnits += valueWithUnit;
155 if (*
i == separator) {
157 }
else if (*
i ==
'\0') {
163 switch (partsPresent) {
186 stringstream s(stringstream::in | stringstream::out);
190 positive.m_ticks = -positive.m_ticks;
194 s << setfill(
'0') << setw(2) << floor(positive.
totalHours()) <<
":" << setw(2) << positive.
minutes() <<
":" << setw(2) << positive.
seconds();
199 if (milli || micro || nano) {
200 s <<
'.' << setw(3) << milli;
202 s << setw(3) << micro;
218 bool needWhitespace =
false;
219 if (
const int days = positive.
days()) {
220 needWhitespace =
true;
226 needWhitespace =
true;
232 needWhitespace =
true;
238 needWhitespace =
true;
245 needWhitespace =
true;
251 needWhitespace =
true;
265 s << setprecision(0);
267 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...
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 provided by the c++utilities library.
TimeSpanOutputFormat
Specifies the output format.
StringType argsToString(Args &&...args)