I use Qt 5.7.1 on Windows, 64 bits version. In my application, I manage some date time with different time zone.
I've recently seen some strange behaviour, and here is a simple code to test it :
QDateTime ParisDate(QDate(2016, 1, 20), QTime(2, 0, 0), QTimeZone("Europe/Paris"));
QDateTime PerthDate(QDate(2016, 1, 20), QTime(9, 0, 0), QTimeZone("Australia/Perth"));
QDateTime ParisConvertedToPerth = ParisDate.toTimeZone(QTimeZone("Australia/Perth"));
qDebug() << " ParisDate = " << ParisDate;
qDebug() << " PerthDate = " << PerthDate;
qDebug() << " delta Paris => Perth = " << ParisDate.secsTo(PerthDate) / 3600;
qDebug() << " delta ParisConvertedToPerth => Perth = " << ParisConvertedToPerth.secsTo(PerthDate) / 3600;
qDebug() << " ParisDate to UTC = " << ParisDate.toUTC();
qDebug() << " PerthDate to UTC = " << PerthDate.toUTC();
qDebug() << " ParisConvertedToPerth to UTC = " << ParisConvertedToPerth.toUTC();
This produce the following output :
ParisDate = QDateTime(2016-01-20 02:00:00.000 Paris, Madrid Qt::TimeSpec(TimeZone) Europe/Paris)
PerthDate = QDateTime(2016-01-20 09:00:00.000 Australie (Ouest) Qt::TimeSpec(TimeZone) Australia/Perth)
delta Paris => Perth = 8
delta ParisConvertedToPerth => Perth = 0
ParisDate to UTC = QDateTime(2016-01-20 01:00:00.000 UTC Qt::TimeSpec(UTC))
PerthDate to UTC = QDateTime(2016-01-20 09:00:00.000 UTC Qt::TimeSpec(UTC))
ParisConvertedToPerth to UTC = QDateTime(2016-01-20 09:00:00.000 UTC Qt::TimeSpec(UTC))
I don't understand, because I thought that the 2 variables "ParisDate" and "PerthDate" should refer to the same point in time, exprimed with a different time zone.
So I believe the "delta Paris => Perth" should be 0 hours.
I can't believe the Qt5 code is broken, so what did I miss here ?