From fcb423d1f25bd3e283c2023d988ed54921fcd12d Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 2 Jun 2017 15:18:43 +0200 Subject: Q(Date|Time)+: in QDebug's <<, handle invalid explicitly The output didn't previously make clear that the datum was invalid. It's now explicitly invalid. At the same time, use QDebug's space() and nospace() methods to make spacing choices explicit. Revised a QDate test to match. Change-Id: I4699f5897530b4caa31c22fdb07de149832b30f4 Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetime.cpp | 48 ++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 17 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 5677f35bc9..5b15ffad9d 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -5303,39 +5303,53 @@ QDataStream &operator>>(QDataStream &in, QDateTime &dateTime) QDebug operator<<(QDebug dbg, const QDate &date) { QDebugStateSaver saver(dbg); - dbg.nospace() << "QDate(" << date.toString(Qt::ISODate) << ')'; + dbg.nospace() << "QDate("; + if (date.isValid()) + dbg.nospace() << date.toString(Qt::ISODate); + else + dbg.nospace() << "Invalid"; + dbg.nospace() << ')'; return dbg; } QDebug operator<<(QDebug dbg, const QTime &time) { QDebugStateSaver saver(dbg); - dbg.nospace() << "QTime(" << time.toString(QStringViewLiteral("HH:mm:ss.zzz")) << ')'; + dbg.nospace() << "QTime("; + if (time.isValid()) + dbg.nospace() << time.toString(QStringViewLiteral("HH:mm:ss.zzz")); + else + dbg.nospace() << "Invalid"; + dbg.nospace() << ')'; return dbg; } QDebug operator<<(QDebug dbg, const QDateTime &date) { QDebugStateSaver saver(dbg); - const Qt::TimeSpec ts = date.timeSpec(); dbg.nospace() << "QDateTime("; - dbg.noquote() << date.toString(QStringViewLiteral("yyyy-MM-dd HH:mm:ss.zzz t")) - << ' ' << ts; - switch (ts) { - case Qt::UTC: - break; - case Qt::OffsetFromUTC: - dbg << ' ' << date.offsetFromUtc() << 's'; - break; - case Qt::TimeZone: + if (date.isValid()) { + const Qt::TimeSpec ts = date.timeSpec(); + dbg.noquote() << date.toString(QStringViewLiteral("yyyy-MM-dd HH:mm:ss.zzz t")) + << ' ' << ts; + switch (ts) { + case Qt::UTC: + break; + case Qt::OffsetFromUTC: + dbg.space() << date.offsetFromUtc() << 's'; + break; + case Qt::TimeZone: #if QT_CONFIG(timezone) - dbg << ' ' << date.timeZone().id(); + dbg.space() << date.timeZone().id(); #endif // timezone - break; - case Qt::LocalTime: - break; + break; + case Qt::LocalTime: + break; + } + } else { + dbg.nospace() << "Invalid"; } - return dbg << ')'; + return dbg.nospace() << ')'; } #endif -- cgit v1.2.3