+ ts
+ << qSetRealNumberPrecision(precision)
+ << (v * multiplier)
+ << ' '
+ << prefix
+ << unit;
+
+ return s;
+}
+
+QString format_time_si_adjusted(
+ const Timestamp& t,
+ SIPrefix prefix,
+ unsigned precision,
+ QString unit,
+ bool sign)
+{
+ // The precision is always given without taking the prefix into account
+ // so we need to deduct the number of decimals the prefix might imply
+ const int prefix_order = -exponent(prefix);
+
+ const unsigned int relative_prec =
+ (prefix >= SIPrefix::none) ? precision :
+ max((int)(precision - prefix_order), 0);
+
+ return format_time_si(t, prefix, relative_prec, unit, sign);
+}
+
+
+// Helper for 'format_time_minutes()'.
+static QString pad_number(unsigned int number, int length)
+{
+ return QString("%1").arg(number, length, 10, QChar('0'));
+}
+
+QString format_time_minutes(const Timestamp& t, signed precision, bool sign)
+{
+ const Timestamp whole_seconds = floor(abs(t));
+ const Timestamp days = floor(whole_seconds / (60 * 60 * 24));
+ const unsigned int hours = fmod(whole_seconds / (60 * 60), 24).convert_to<uint>();
+ const unsigned int minutes = fmod(whole_seconds / 60, 60).convert_to<uint>();
+ const unsigned int seconds = fmod(whole_seconds, 60).convert_to<uint>();
+
+ QString s;
+ QTextStream ts(&s);
+
+ if (t < 0)
+ ts << "-";
+ else if (sign)
+ ts << "+";
+
+ bool use_padding = false;
+
+ // DD
+ if (days) {
+ ts << days.str().c_str() << ":";
+ use_padding = true;
+ }
+
+ // HH
+ if (hours || days) {
+ ts << pad_number(hours, use_padding ? 2 : 0) << ":";
+ use_padding = true;
+ }
+
+ // MM
+ ts << pad_number(minutes, use_padding ? 2 : 0);
+
+ ts << ":";
+
+ // SS
+ ts << pad_number(seconds, 2);
+
+ if (precision) {
+ ts << ".";
+
+ const Timestamp fraction = fabs(t) - whole_seconds;
+
+ ostringstream ss;
+ ss << fixed << setprecision(precision) << setfill('0') << fraction;
+ string fs = ss.str();
+
+ // Copy all digits, inserting spaces as unit separators
+ for (int i = 1; i <= precision; i++) {
+ // Start at index 2 to skip the "0." at the beginning
+ ts << fs.at(1 + i);
+
+ if ((i > 0) && (i % 3 == 0) && (i != precision))
+ ts << " ";
+ }