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 <edward.welbourne@qt.io>
This commit is contained in:
Ahmad Samir 2023-03-28 19:32:07 +02:00
parent fa9244700e
commit b490bd0265

View File

@ -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() << ')';