-static const QString SIPrefixes[17] =
- {"y", "z", "a", "f", "p", "n", QChar(0x03BC), "m", "", "k", "M", "G",
- "T", "P", "E", "Z", "Y"};
-const int FirstSIPrefix = 8;
-const int FirstSIPrefixPower = -(FirstSIPrefix * 3);
+static const QString SIPrefixes[17] = {
+ "y", "z",
+ "a", "f", "p",
+ "n", QChar(0x03BC), "m",
+ "",
+ "k", "M", "G",
+ "T", "P", "E",
+ "Z", "Y"};
+const int EmptySIPrefix = 8;
+const int FirstSIPrefixPower = -(EmptySIPrefix * 3);
+
+// Insert the timestamp value into the stream in fixed-point notation
+// (and honor the precision)
+static QTextStream& operator<<(QTextStream& stream, const Timestamp& t)
+{
+ // The multiprecision types already have a function and a stream insertion
+ // operator to convert them to a string, however these functions abuse a
+ // precision value of zero to print all available decimal places instead of
+ // none, and the boost authors refuse to fix this because they don't want
+ // to break buggy code that relies on this bug.
+ // (https://svn.boost.org/trac/boost/ticket/10103)
+ // Therefore we have to work around the case where precision is zero.
+
+ int precision = stream.realNumberPrecision();
+
+ std::ostringstream ss;
+ ss << std::fixed;
+
+ if (stream.numberFlags() & QTextStream::ForceSign) {
+ ss << std::showpos;
+ }
+
+ if (0 == precision) {
+ ss
+ << std::setprecision(1)
+ << round(t);
+ } else {
+ ss
+ << std::setprecision(precision)
+ << t;
+ }
+
+ std::string str(ss.str());
+ if (0 == precision) {
+ // remove the separator and the unwanted decimal place
+ str.resize(str.size() - 2);
+ }
+
+ return stream << QString::fromStdString(str);
+}