diff options
-rw-r--r-- | src/corelib/tools/qdatetime.cpp | 21 | ||||
-rw-r--r-- | src/corelib/tools/qdatetime.h | 4 | ||||
-rw-r--r-- | tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp | 4 |
3 files changed, 25 insertions, 4 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 3e5600b484..ab5a516e8a 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -4391,19 +4391,34 @@ void QDateTimePrivate::getUTC(QDate &outDate, QTime &outTime) const #if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_NO_DATESTRING) QDebug operator<<(QDebug dbg, const QDate &date) { - dbg.nospace() << "QDate(" << date.toString() << ')'; + dbg.nospace() << "QDate(" << date.toString(QStringLiteral("yyyy-MM-dd")) << ')'; return dbg.space(); } QDebug operator<<(QDebug dbg, const QTime &time) { - dbg.nospace() << "QTime(" << time.toString() << ')'; + dbg.nospace() << "QTime(" << time.toString(QStringLiteral("HH:mm:ss.zzz")) << ')'; return dbg.space(); } QDebug operator<<(QDebug dbg, const QDateTime &date) { - dbg.nospace() << "QDateTime(" << date.toString() << ')'; + QString spec; + switch (date.d->spec) { + case QDateTimePrivate::UTC : + spec = QStringLiteral(" Qt::UTC"); + break; + case QDateTimePrivate::OffsetFromUTC : + spec = QString::fromUtf8(" Qt::OffsetFromUTC %1s").arg(date.offsetFromUtc()); + break; + case QDateTimePrivate::LocalDST : + case QDateTimePrivate::LocalStandard : + case QDateTimePrivate::LocalUnknown : + default : + spec = QStringLiteral(" Qt::LocalTime"); + } + QString output = date.toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz t")) + spec; + dbg.nospace() << "QDateTime(" << output << ')'; return dbg.space(); } #endif diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h index 25f5b74eb2..8b63c5a377 100644 --- a/src/corelib/tools/qdatetime.h +++ b/src/corelib/tools/qdatetime.h @@ -293,6 +293,10 @@ private: friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QDateTime &); friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QDateTime &); #endif + +#if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_NO_DATESTRING) + friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QDateTime &); +#endif }; Q_DECLARE_SHARED(QDateTime) diff --git a/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp b/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp index f1df6187d0..becff75836 100644 --- a/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp +++ b/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp @@ -72,7 +72,9 @@ void tst_QNoDebug::noDebugOutput() const void tst_QNoDebug::streaming() const { QDateTime dt(QDate(1,2,3),QTime(4,5,6)); - QTest::ignoreMessage(QtWarningMsg, qPrintable(QString::fromLatin1("QDateTime(\"%1\") ").arg(dt.toString()))); + QString debugString = dt.toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz t")) + + QStringLiteral(" Qt::LocalTime"); + QTest::ignoreMessage(QtWarningMsg, qPrintable(QString::fromLatin1("QDateTime(\"%1\") ").arg(debugString))); qWarning() << dt; } |