summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qtimezone.cpp8
-rw-r--r--tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp16
2 files changed, 22 insertions, 2 deletions
diff --git a/src/corelib/tools/qtimezone.cpp b/src/corelib/tools/qtimezone.cpp
index ec2f7c4af6..c4cd76c59c 100644
--- a/src/corelib/tools/qtimezone.cpp
+++ b/src/corelib/tools/qtimezone.cpp
@@ -961,7 +961,13 @@ QDataStream &operator>>(QDataStream &ds, QTimeZone &tz)
int country;
QString comment;
ds >> ianaId >> utcOffset >> name >> abbreviation >> country >> comment;
- tz = QTimeZone(ianaId.toUtf8(), utcOffset, name, abbreviation, (QLocale::Country) country, comment);
+ // Try creating as a system timezone, which succeeds (producing a valid
+ // zone) iff ianaId is valid; we can then ignore the other data.
+ tz = QTimeZone(ianaId.toUtf8());
+ // If not, then construct a custom timezone using all the saved values:
+ if (!tz.isValid())
+ tz = QTimeZone(ianaId.toUtf8(), utcOffset, name, abbreviation,
+ QLocale::Country(country), comment);
} else {
tz = QTimeZone(ianaId.toUtf8());
}
diff --git a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp
index c1f2822b74..e75ed5cc67 100644
--- a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp
+++ b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp
@@ -299,7 +299,7 @@ void tst_QTimeZone::nullTest()
void tst_QTimeZone::dataStreamTest()
{
- // Test the OffsetFromUtc backend serialization
+ // Test the OffsetFromUtc backend serialization. First with a custom timezone:
QTimeZone tz1("QST", 123456, "Qt Standard Time", "QST", QLocale::Norway, "Qt Testing");
QByteArray tmp;
{
@@ -321,6 +321,20 @@ void tst_QTimeZone::dataStreamTest()
QString("Qt Standard Time"));
QCOMPARE(tz2.offsetFromUtc(QDateTime::currentDateTime()), 123456);
+ // And then with a standard IANA timezone (QTBUG-60595):
+ tz1 = QTimeZone("UTC");
+ QCOMPARE(tz1.isValid(), true);
+ {
+ QDataStream ds(&tmp, QIODevice::WriteOnly);
+ ds << tz1;
+ }
+ {
+ QDataStream ds(&tmp, QIODevice::ReadOnly);
+ ds >> tz2;
+ }
+ QCOMPARE(tz2.isValid(), true);
+ QCOMPARE(tz2.id(), tz1.id());
+
// Test the system backend serialization
tz1 = QTimeZone("Pacific/Auckland");