Skip to content

Commit

Permalink
Return const QString for invalid duration value
Browse files Browse the repository at this point in the history
  • Loading branch information
benis committed Jan 13, 2019
1 parent 9977df3 commit 5ba36de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/util/duration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static const qint64 kSecondsPerDay = 24 * kSecondsPerHour;
} // namespace

// static
const QString DurationBase::kInvalidDurationString = "?";
// Unicode for thin space
QChar DurationBase::kKiloGroupSeparator = QChar(0x2009);
// Unicode for bottom left corner
Expand All @@ -29,7 +30,7 @@ QChar DurationBase::kDecimalSeparator = QChar(0x002E);
QString DurationBase::formatTime(double dSeconds, Precision precision) {
if (dSeconds < 0.0) {
// negative durations are not supported
return "?";
return kInvalidDurationString;
}

const qint64 days = static_cast<qint64>(std::floor(dSeconds)) / kSecondsPerDay;
Expand Down Expand Up @@ -61,7 +62,7 @@ QString DurationBase::formatTime(double dSeconds, Precision precision) {
QString DurationBase::formatSeconds(double dSeconds, Precision precision) {
if (dSeconds < 0.0) {
// negative durations are not supported
return "?";
return kInvalidDurationString;
}

QString durationString;
Expand All @@ -81,7 +82,7 @@ QString DurationBase::formatSeconds(double dSeconds, Precision precision) {
QString DurationBase::formatKiloSeconds(double dSeconds, Precision precision) {
if (dSeconds < 0.0) {
// negative durations are not supported
return "?";
return kInvalidDurationString;
}

int kilos = (int)dSeconds / 1000;
Expand All @@ -108,7 +109,7 @@ QString DurationBase::formatKiloSeconds(double dSeconds, Precision precision) {
QString DurationBase::formatHectoSeconds(double dSeconds, Precision precision) {
if (dSeconds < 0.0) {
// negative durations are not supported
return "?";
return kInvalidDurationString;
}

int hectos = (int)dSeconds / 100;
Expand Down
2 changes: 2 additions & 0 deletions src/util/duration.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace mixxx {
class DurationBase {

public:

enum Units {
SECONDS,
MILLIS,
Expand Down Expand Up @@ -89,6 +90,7 @@ class DurationBase {
static constexpr qint64 kNanosPerSecond = kMicrosPerSecond * 1000;
static constexpr qint64 kNanosPerMilli = kNanosPerSecond / 1000;
static constexpr qint64 kNanosPerMicro = kNanosPerMilli / 1000;
static const QString kInvalidDurationString;
static QChar kKiloGroupSeparator;
static QChar kHectoGroupSeparator;
static QChar kDecimalSeparator;
Expand Down

0 comments on commit 5ba36de

Please sign in to comment.