From b490bd0265491e8af0bcb1c08159a3a23ac4331e Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Tue, 28 Mar 2023 19:32:07 +0200 Subject: [PATCH] QDate: fix QDebug operator<<() for dates with year > 9999 ISODate only supports years in the range 0-9999; instead of printing an empty string, use date.toString(Qt::TextDate) instead. This is mostly useful for debugging DateTime unittests. Change-Id: Id09951ce0a15452e28cb41a3b918c5ef05caab09 Reviewed-by: Edward Welbourne --- src/corelib/time/qdatetime.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index b484196350..05031e22db 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -5625,7 +5625,11 @@ QDebug operator<<(QDebug dbg, QDate date) QDebugStateSaver saver(dbg); dbg.nospace() << "QDate("; if (date.isValid()) - dbg.nospace() << date.toString(Qt::ISODate); + // QTBUG-91070, ISODate only supports years in the range 0-9999 + if (int y = date.year(); y > 0 && y <= 9999) + dbg.nospace() << date.toString(Qt::ISODate); + else + dbg.nospace() << date.toString(Qt::TextDate); else dbg.nospace() << "Invalid"; dbg.nospace() << ')';