From 517578e0712732ad43f21b6a655ba5e70ada6ab7 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 12 Feb 2021 13:26:37 +0100 Subject: QDateTime::toString(): use UTC-offset as time-zone suffix Since fromString() can't parse the (ambiguous at the best of times; also backend-dependent and thus potentially system-locale-dependent) abbreviations currently produced (since 5.9) and can parse UTC-based offsets, the OffsetName of the zone is a more robust format for the zone-suffix. This also makes it possible to consistently use the C locale, compatibly with everything else about post-6.0 date-time serialization. [ChangeLog][QtCore][QDateTime] When spec is Qt::TimeZone, the offset-suffix now used for the toString(Qt::TextDate) format is now a UTC-based offset string, compatible with the parsing (now) supported by fromString(). The zone-abbreviation suffix in use since 5.9 was not parseable. Change-Id: I4024ae87980c6d3590c68a67b8d1c8f433e36855 Reviewed-by: Thiago Macieira --- tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 4bf78cb93a..2bf93c3ce0 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -940,9 +940,6 @@ void tst_QDateTime::toString_textDate_extra() QVERIFY(!endsWithGmt(dt)); #if QT_CONFIG(timezone) -# if defined Q_OS_UNIX && !defined Q_OS_DARWIN && !defined Q_OS_ANDROID -# define CORRECT_ZONE_ABBREV -# endif // QTBUG-57320, QTBUG-57298, QTBUG-68833 if (QTimeZone::systemTimeZone().offsetFromUtc(dt)) QVERIFY(dt.toString() != QLatin1String("Thu Jan 1 00:00:00 1970")); else @@ -951,11 +948,7 @@ void tst_QDateTime::toString_textDate_extra() QTimeZone PST("America/Vancouver"); if (PST.isValid()) { dt = QDateTime::fromMSecsSinceEpoch(0, PST); -# ifdef CORRECT_ZONE_ABBREV - QCOMPARE(dt.toString(), QLatin1String("Wed Dec 31 16:00:00 1969 PST")); -# else - QVERIFY(dt.toString().startsWith(QLatin1String("Wed Dec 31 16:00:00 1969 "))); -# endif + QCOMPARE(dt.toString(), QLatin1String("Wed Dec 31 16:00:00 1969 UTC-08:00")); dt = dt.toLocalTime(); QVERIFY(!endsWithGmt(dt)); } else { @@ -964,11 +957,7 @@ void tst_QDateTime::toString_textDate_extra() QTimeZone CET("Europe/Berlin"); if (CET.isValid()) { dt = QDateTime::fromMSecsSinceEpoch(0, CET); -# ifdef CORRECT_ZONE_ABBREV - QCOMPARE(dt.toString(), QLatin1String("Thu Jan 1 01:00:00 1970 CET")); -# else - QVERIFY(dt.toString().startsWith(QLatin1String("Thu Jan 1 01:00:00 1970 "))); -# endif + QCOMPARE(dt.toString(), QLatin1String("Thu Jan 1 01:00:00 1970 UTC+01:00")); dt = dt.toLocalTime(); QVERIFY(!endsWithGmt(dt)); } else { -- cgit v1.2.3