15 namespace swift::misc::physical_quantities
19 bool negative = (hours < 0);
20 double value = qAbs(hours) + minutes / 100.0 + seconds / 10000.0;
58 (*this) =
CTime(hour, minute, second);
68 if (hhmm.
length() != 4) {
return false; }
73 const int h = hStr.
toInt(&ok);
74 if (!ok || h < 0 || h > 23) {
return false; }
76 const int m = mStr.
toInt(&ok);
77 if (!ok || m < 0 || m > 59) {
return false; }
79 *
this =
CTime(h, m, 0);
94 const double currentValue = copy.
value();
96 const double remaining = std::fmod(currentValue, 3600);
101 parts << qRound(hr) << qRound(mi) << qRound(se);
112 const QString fs = QStringLiteral(
"%1:%2:%3").
arg(h, m, s);
120 return static_cast<int>(ms);
126 return static_cast<int>(ms);
134 const QString fs = QStringLiteral(
"%1:%2").
arg(h, m);
149 const QTime t(parts[0], parts[1], parts[2]);
static double trunc(double value, double epsilon=1e-10)
Nearest integer not greater in magnitude than value, correcting for epsilon.
A physical quantity such as "5m", "20s", "1500ft/s".
double value() const
Value in current unit.
bool isNegativeWithEpsilonConsidered() const
Value <= 0 epsilon considered.
void setValueSameUnit(double value)
Change value without changing unit.
void parseFromString(const QString &value)
Parse value from string.
PQ & switchUnit(const MU &newUnit)
Change unit, and convert value to maintain the same quantity.
double value(MU unit) const
Value in given unit.
double valueRounded(CTimeUnit unit, int digits=-1) const
Rounded value in given unit.
const CTime & makeNegative()
Make value always negative.
SeparatorMode
Number separators / group separators.
void parseFromString(const QString &time)
From string hh:mm, or hh:mm:ss, or time units such as s, min.
int toMs() const
Convenience functions when used with timers etc.
QList< int > getHrsMinSecParts() const
Parts hh, mm, ss.
QString formattedHrsMin() const
Formatted as hh:mm.
int toSeconds() const
Convenience functions when used with timers etc.
QDateTime toQDateTime() const
To Qt date time.
CTime()
Default constructor.
QTime toQTime() const
To Qt time.
bool parseFromString_hhmm(const QString &hhmm)
From string like 2211 (hhmm)
QString formattedHrsMinSec() const
Formatted as hh:mm:ss.
Specialized class for time units (ms, hour, min).
static CTimeUnit hrmin()
Hours, minutes.
static CTimeUnit hms()
Hours, minutes, seconds.
static CTimeUnit s()
Second s.
static CTimeUnit ms()
Millisecond ms.
static CTimeUnit h()
Hour.
QDateTime currentDateTimeUtc()
void setTime(QTime time, QDateTime::TransitionResolution resolve)
QList< T >::const_reference at(qsizetype i) const const
QString & append(QChar ch)
QString arg(Args &&... args) const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString left(qsizetype n) &&
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) &&
QString number(double n, char format, int precision)
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QString right(qsizetype n) &&
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
int toInt(bool *ok, int base) const const
QString trimmed() const const