31#include "kanoopcommon.h"
58 TimeSpan(
double days,
double hours,
double minutes,
double seconds,
double milliseconds = 0,
double microseconds = 0,
double nanoseconds = 0);
288 bool isZero()
const {
return _nanoseconds == 0; }
405 QVariant
toVariant()
const {
return QVariant::fromValue<TimeSpan>(*
this); }
490 static TimeSpan diff(std::chrono::system_clock::time_point now, std::chrono::system_clock::time_point then);
506 static TimeSpan absDiff(std::chrono::system_clock::time_point t1, std::chrono::system_clock::time_point t2);
525 static TimeSpan parseAbbreviatedString(
const QString& timeString,
bool* parsed =
nullptr);
526 static TimeSpan parseColonDelimitedString(
const QString& timeString,
bool* parsed =
nullptr);
527 static TimeSpan parseMicrosecondString(
const QString& timeString,
bool* parsed =
nullptr);
528 static TimeSpan parseMillisecondString(
const QString& timeString,
bool* parsed =
nullptr);
529 static QStringList getTokens(
const QString &timeString);
530 static int parseIntToToken(QString &remaining,
const QString &until);
536 static const double NanosecondsPerMicrosecond;
537 static const double NanosecondsPerMillisecond;
538 static const double NanosecondsPerSecond;
539 static const double NanosecondsPerMinute;
540 static const double NanosecondsPerHour;
541 static const double NanosecondsPerDay;
543 static const double MicrosecondsPerMillisecond;
544 static const double MicrosecondsPerSecond;
545 static const double MicrosecondsPerMinute;
546 static const double MicrosecondsPerHour;
547 static const double MicrosecondsPerDay;
549 static const double MillisecondsPerSecond;
550 static const double MillisecondsPerMinute;
551 static const double MillisecondsPerHour;
552 static const double MillisecondsPerDay;
554 static const double SecondsPerMinute;
555 static const double SecondsPerHour;
556 static const double SecondsPerDay;
558 static const double MinutesPerHour;
559 static const double MinutesPerDay;
561 static const double HoursPerDay;
563 static const double DaysPerYear;
void operator/=(const TimeSpan &other)
Divide-assign by a TimeSpan.
static TimeSpan fromVariant(const QVariant &value)
Construct a TimeSpan from a QVariant holding a TimeSpan value.
bool isPositive() const
Return true if this time span represents a positive (non-zero) duration.
static TimeSpan fromNanoseconds(double nanoseconds)
Construct a TimeSpan from a nanosecond count.
qint64 minutes() const
minutes
bool isZero() const
Is this timespan zero total nanoseconds.
qint64 days() const
Return the number of whole days in the days field of this TimeSpan when printed.
TimeSpan addNanoseconds(double nanoseconds) const
Return a new TimeSpan with nanoseconds added.
static TimeSpan absDiff(const QDateTime &t1, const QDateTime &t2)
Compute the absolute (non-negative) difference between two QDateTime values.
static TimeSpan fromMilliseconds(double milliseconds)
Construct a TimeSpan from a millisecond count.
TimeSpan(double days, double hours, double minutes, double seconds, double milliseconds=0, double microseconds=0, double nanoseconds=0)
Construct a TimeSpan from explicit time components.
static TimeSpan fromString(const QString &timeString, bool *parsed=nullptr)
Parse a TimeSpan from a formatted duration string.
TimeSpan addHours(double hours) const
Return a new TimeSpan with hours added.
static TimeSpan fromDays(double days)
Construct a TimeSpan from a day count.
TimeSpan & operator=(const timespec &other)
Assign from a POSIX timespec.
static TimeSpan fromMicroseconds(double microseconds)
Construct a TimeSpan from a microsecond count.
qint64 seconds() const
seconds
TimeSpan addMicroseconds(double microseconds) const
Return a new TimeSpan with microseconds added.
double totalMicroseconds() const
totalMicroseconds
TimeSpan operator/(double value) const
Divide by a scalar factor.
TimeSpan addMinutes(double minutes) const
Return a new TimeSpan with minutes added.
TimeSpan & operator=(const TimeSpan &other)
Copy-assign from another TimeSpan.
QVariant toVariant() const
Wrap this TimeSpan in a QVariant for storage or signal passing.
TimeSpan operator+(const TimeSpan &other) const
Add two time spans.
qint64 nanoseconds() const
nanoseconds
double totalDays() const
totalDays
TimeSpan addDays(double days) const
Return a new TimeSpan with days added.
double totalMinutes() const
totalMinutes
double totalMilliseconds() const
totalMilliseconds
bool isNegative() const
Return true if this time span represents a negative duration.
static TimeSpan min(const TimeSpan &t1, const TimeSpan &t2)
Return the smaller of two time spans.
bool operator<=(const TimeSpan &other) const
Less-than-or-equal comparison.
TimeSpan(const timespec &other)
Construct a TimeSpan from a POSIX timespec value.
TimeSpan operator/(const TimeSpan &other) const
Divide two time spans component-wise.
void operator*=(const TimeSpan &other)
Multiply-assign by a TimeSpan.
TimeSpan(const TimeSpan &other)
Copy constructor.
static TimeSpan max(const TimeSpan &t1, const TimeSpan &t2)
Return the larger of two time spans.
TimeSpan operator*(const TimeSpan &other) const
Multiply two time spans component-wise.
static TimeSpan fromHours(double hours)
Construct a TimeSpan from an hour count.
qint64 milliseconds() const
milliseconds
void toTimeSpec(struct timespec ×pec) const
Populate a POSIX timespec structure from this TimeSpan.
bool operator==(const TimeSpan &other) const
Equality comparison.
double totalSeconds() const
totalSeconds
void operator+=(const TimeSpan &other)
Add-assign a TimeSpan.
qint64 hours() const
hours
double totalHours() const
totalHours
bool operator!=(const TimeSpan &other) const
Inequality comparison.
TimeSpan()
Default constructor — creates a zero-length time span.
static TimeSpan zero()
Return a zero-length TimeSpan.
void operator/=(double value)
Divide-assign by a scalar.
QString toString(bool microseconds=false) const
Format this TimeSpan as a string using the Auto format.
static TimeSpan diff(std::chrono::system_clock::time_point now, std::chrono::system_clock::time_point then)
Compute the signed difference between two chrono time points (now − then).
bool operator<(const TimeSpan &other) const
Less-than comparison.
TimeSpan operator-(const TimeSpan &other) const
Subtract a time span.
bool operator>=(const TimeSpan &other) const
Greater-than-or-equal comparison.
Format
Output format for toString().
@ Milliseconds
Display with millisecond precision.
@ NoMilliseconds
Display without sub-second components.
@ Abbreviated
Abbreviated format (e.g. "1h 2m 3s")
@ MicroSeconds
Display with microsecond precision.
@ Auto
Choose format automatically based on the span's magnitude.
TimeSpan operator*(double value) const
Scale by a scalar factor.
static TimeSpan diff(const QDateTime &now, const QDateTime &then)
Compute the signed difference between two QDateTime values (now − then).
qint64 microseconds() const
microseconds
bool isValid() const
Return true if this time span was successfully constructed or parsed.
void operator*=(double value)
Multiply-assign by a scalar.
QString toAbbreviatedFormat(bool showMilliseconds=false) const
Format this TimeSpan using the abbreviated display format (e.g.
static TimeSpan fromSeconds(double seconds)
Construct a TimeSpan from a second count.
QString toString(Format format, bool microseconds=false) const
Format this TimeSpan as a string in the specified format.
double totalNanoseconds() const
totalNanoseconds
TimeSpan addSeconds(double seconds) const
Return a new TimeSpan with seconds added.
TimeSpan absoluteValue() const
Return the absolute value of this time span.
static TimeSpan invalid()
Return an invalid (sentinel) TimeSpan whose isValid() returns false.
static TimeSpan fromMinutes(double minutes)
Construct a TimeSpan from a minute count.
TimeSpan addMilliseconds(double milliseconds) const
Return a new TimeSpan with milliseconds added.
void operator-=(const TimeSpan &other)
Subtract-assign a TimeSpan.
bool operator>(const TimeSpan &other) const
Greater-than comparison.
static TimeSpan absDiff(std::chrono::system_clock::time_point t1, std::chrono::system_clock::time_point t2)
Compute the absolute difference between two chrono time points.
QString toDumpString() const
Format this TimeSpan as a verbose diagnostic string showing all internal fields.