From 83315ce8b2b5c314fef2382f5ef5344de59fe3e3 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Mon, 22 Apr 2013 14:28:24 +0200 Subject: Revert QDateTime serialisation to pre-Qt 5 behaviour. In Qt 5, I managed to break the guarantee that a deserialised local datetime is the same time of day (potentially different UTC time), regardless of which timezone it was serialised in. This happened after I fixed QTBUG-4057 with If650e7960dca7b6ab44b8233410a6369c41df73a, which serialised datetimes as UTC. This patch reverts QDateTime serialisation to pre-Qt 5 behaviour to restore the guarantee and consequently re-opens QTBUG-4057. Change-Id: Iea877f7ed886f530b928067789b53534e89fe8cb Reviewed-by: Thiago Macieira --- src/corelib/io/qdatastream.cpp | 3 ++- src/corelib/io/qdatastream.h | 2 +- src/corelib/tools/qdatetime.cpp | 7 +++++-- 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qdatastream.cpp b/src/corelib/io/qdatastream.cpp index dc7387bc85..b6926bc544 100644 --- a/src/corelib/io/qdatastream.cpp +++ b/src/corelib/io/qdatastream.cpp @@ -539,7 +539,7 @@ void QDataStream::setByteOrder(ByteOrder bo) \value Qt_4_8 Same as Qt_4_6. \value Qt_4_9 Same as Qt_4_6. \value Qt_5_0 Version 13 (Qt 5.0) - \value Qt_5_1 Same as Qt_5_0. + \value Qt_5_1 Version 14 (Qt 5.1) \sa setVersion(), version() */ @@ -571,6 +571,7 @@ void QDataStream::setByteOrder(ByteOrder bo) \table \header \li Qt Version \li QDataStream Version + \row \li Qt 5.1 \li 14 \row \li Qt 5.0 \li 13 \row \li Qt 4.6 \li 12 \row \li Qt 4.5 \li 11 diff --git a/src/corelib/io/qdatastream.h b/src/corelib/io/qdatastream.h index 6017ba5e7d..969cdf4517 100644 --- a/src/corelib/io/qdatastream.h +++ b/src/corelib/io/qdatastream.h @@ -86,7 +86,7 @@ public: Qt_4_8 = Qt_4_7, Qt_4_9 = Qt_4_8, Qt_5_0 = 13, - Qt_5_1 = Qt_5_0 + Qt_5_1 = 14 #if QT_VERSION >= 0x050200 #error Add the datastream version for this Qt version #endif diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 07b617ee2e..d8e3a78cdf 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -3691,8 +3691,11 @@ QDataStream &operator>>(QDataStream &in, QTime &time) */ QDataStream &operator<<(QDataStream &out, const QDateTime &dateTime) { - if (out.version() >= 13) { + if (out.version() == 13) { if (dateTime.isValid()) { + // This approach is wrong and should not be used again; it breaks + // the guarantee that a deserialised local datetime is the same time + // of day, regardless of which timezone it was serialised in. QDateTime asUTC = dateTime.toUTC(); out << asUTC.d->date << asUTC.d->time; } else { @@ -3721,7 +3724,7 @@ QDataStream &operator>>(QDataStream &in, QDateTime &dateTime) in >> dateTime.d->date >> dateTime.d->time; - if (in.version() >= 13) { + if (in.version() == 13) { qint8 ts = 0; in >> ts; if (dateTime.isValid()) { -- cgit v1.2.3