15 namespace swift::misc::physical_quantities
19 bool negative = (hours < 0);
20 double value = qAbs(hours) + minutes / 100.0 + seconds / 10000.0;
34 CTime converted(time.hour(), time.minute(), time.second());
41 QString ts = time.trimmed();
45 if (ts.startsWith(
'+')) { ts.remove(0, 1); }
46 else if (ts.startsWith(
'-'))
52 if (ts.contains(
":") && (ts.length() == 8 || ts.length() == 5))
54 const int hour = QStringView { ts }.mid(0, 2).toInt();
55 const int minute = QStringView { ts }.mid(3, 2).toInt();
57 if (ts.length() == 8) second = QStringView { ts }.mid(6, 2).toInt();
58 (*this) =
CTime(hour, minute, second);
68 if (hhmm.length() != 4) {
return false; }
69 const QString hStr = hhmm.left(2);
70 const QString mStr = hhmm.right(2);
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);
108 const QString h = QStringLiteral(
"00%1").arg(QString::number(parts.at(0))).right(2);
109 const QString m = QStringLiteral(
"00%1").arg(QString::number(parts.at(1))).right(2);
110 const QString s = QStringLiteral(
"00%1").arg(QString::number(parts.at(2))).right(2);
112 const QString fs = QStringLiteral(
"%1:%2:%3").arg(h, m, s);
120 return static_cast<int>(ms);
126 return static_cast<int>(ms);
132 const QString h = QStringLiteral(
"00%1").arg(QString::number(parts.at(0))).right(2);
133 const QString m = QStringLiteral(
"00%1").arg(QString::number(parts.at(1))).right(2);
134 const QString fs = QStringLiteral(
"%1:%2").arg(h, m);
141 QDateTime dt = QDateTime::currentDateTimeUtc();
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.