3 #include "../conversion/stringconversion.h" 23 TimeSpan TimeSpan::fromString(
const char *str,
char separator)
31 for (
const char *i = str; *i; ++i) {
32 *i == separator && ++partsSize;
34 parts.reserve(partsSize);
36 for (
const char *i = str;;) {
37 if (*i == separator) {
38 parts.emplace_back(stringToNumber<double>(
string(str, i)));
40 }
else if (*i ==
'\0') {
41 parts.emplace_back(stringToNumber<double>(
string(str, i)));
48 switch (parts.size()) {
50 return TimeSpan::fromSeconds(parts.front());
52 return TimeSpan::fromMinutes(parts.front()) + TimeSpan::fromSeconds(parts[1]);
54 return TimeSpan::fromHours(parts.front()) + TimeSpan::fromMinutes(parts[1]) + TimeSpan::fromSeconds(parts[2]);
56 return TimeSpan::fromDays(parts.front()) + TimeSpan::fromHours(parts[1]) + TimeSpan::fromMinutes(parts[2]) + TimeSpan::fromSeconds(parts[3]);
69 toString(result, format, noMilliseconds);
83 stringstream s(stringstream::in | stringstream::out);
87 positive.m_ticks = -positive.m_ticks;
90 case TimeSpanOutputFormat::Normal:
91 s << setfill(
'0') << setw(2) << floor(positive.
totalHours()) <<
":" << setw(2) << positive.
minutes() <<
":" << setw(2) << positive.
seconds()
94 case TimeSpanOutputFormat::WithMeasures:
99 s << setprecision(2) << (m_ticks / 10.0) <<
" µs ";
101 if (
const int days = positive.
days()) {
104 if (
const int hours = positive.
hours()) {
107 if (
const int minutes = positive.
minutes()) {
108 s << minutes <<
" min ";
110 if (
const int seconds = positive.
seconds()) {
111 s << seconds <<
" s ";
113 if (!noMilliseconds) {
115 s << milliseconds <<
" ms ";
122 result = s.str().substr(0, static_cast<string::size_type>(s.tellp()) - 1);
TimeSpanOutputFormat
Specifies the output format.
constexpr double totalMilliseconds() const
Gets the value of the current TimeSpan class expressed in whole and fractional milliseconds.
constexpr bool isNegative() const
Returns ture if the time interval represented by the current TimeSpan class is negative.
Contains classes providing a means for handling date and time information.
constexpr int days() const
Gets the days component of the time interval represented by the current TimeSpan class.
Represents a time interval.
constexpr int hours() const
Gets the hours component of the time interval represented by the current TimeSpan class...
constexpr double totalHours() const
Gets the value of the current TimeSpan class expressed in whole and fractional hours.
constexpr int minutes() const
Gets the minutes component of the time interval represented by the current TimeSpan class...
Contains several functions providing conversions between different data types.
constexpr int milliseconds() const
Gets the miliseconds component of the time interval represented by the current TimeSpan class...
constexpr int seconds() const
Gets the seconds component of the time interval represented by the current TimeSpan class...