diff options
author | Cesar Garcia Naranjo <cesarg9@gmail.com> | 2015-07-06 13:23:10 +0000 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2015-07-21 22:50:39 +0000 |
commit | 5c67ce5d6da11b8c4e445bba2a3ffb7b6e7f45d9 (patch) | |
tree | a560631109aac3817a9f05dd90f9e5ad9c82a25b | |
parent | 9072edb5f7f2b9f634fac5b5de7090e94ee491f7 (diff) |
QTimeZone: Convert fractional timezones properly.
[ChangeLog][QtCore][QTimeZone] Fixed a wrong timezone conversion when
the POSIX timezone rule contains a fractional timezone (e.g. VET4:30).
Task-number: QTBUG-47037
Change-Id: I5d9052929bbcde174614ccf07c329264603e6431
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/tools/qtimezoneprivate_tz.cpp | 19 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp | 18 |
2 files changed, 31 insertions, 6 deletions
diff --git a/src/corelib/tools/qtimezoneprivate_tz.cpp b/src/corelib/tools/qtimezoneprivate_tz.cpp index 29f0e17012..35380b882a 100644 --- a/src/corelib/tools/qtimezoneprivate_tz.cpp +++ b/src/corelib/tools/qtimezoneprivate_tz.cpp @@ -389,12 +389,19 @@ static int parsePosixOffset(const QByteArray &timeRule) // Format "[+|-]hh[:mm[:ss]]" QList<QByteArray> parts = timeRule.split(':'); int count = parts.count(); - if (count == 3) - return (parts.at(0).toInt() * -60 * 60) + (parts.at(1).toInt() * 60) + parts.at(2).toInt(); - else if (count == 2) - return (parts.at(0).toInt() * -60 * 60) + (parts.at(1).toInt() * 60); - else if (count == 1) - return (parts.at(0).toInt() * -60 * 60); + if (count == 3) { + int hour = parts.at(0).toInt(); + int sign = hour >= 0 ? -1 : 1; + return sign * ((qAbs(hour) * 60 * 60) + (parts.at(1).toInt() * 60) + parts.at(2).toInt()); + } else if (count == 2) { + int hour = parts.at(0).toInt(); + int sign = hour >= 0 ? -1 : 1; + return sign * ((qAbs(hour) * 60 * 60) + (parts.at(1).toInt() * 60)); + } else if (count == 1) { + int hour = parts.at(0).toInt(); + int sign = hour >= 0 ? -1 : 1; + return sign * (qAbs(hour) * 60 * 60); + } return 0; } diff --git a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp index 2af37eb86e..b511abf670 100644 --- a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp +++ b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp @@ -823,6 +823,24 @@ void tst_QTimeZone::tzTest() QCOMPARE(dat.offsetFromUtc, 3600); QCOMPARE(dat.standardTimeOffset, 3600); QCOMPARE(dat.daylightTimeOffset, 0); + + // Test TZ timezone vs UTC timezone for fractionary negative offset + QTzTimeZonePrivate tztz1("America/Caracas"); + QUtcTimeZonePrivate tzutc1("UTC-04:30"); + QVERIFY(tztz1.isValid()); + QVERIFY(tzutc1.isValid()); + QTzTimeZonePrivate::Data datatz1 = tztz1.data(std); + QTzTimeZonePrivate::Data datautc1 = tzutc1.data(std); + QCOMPARE(datatz1.offsetFromUtc, datautc1.offsetFromUtc); + + // Test TZ timezone vs UTC timezone for fractionary positive offset + QTzTimeZonePrivate tztz2("Asia/Calcutta"); + QUtcTimeZonePrivate tzutc2("UTC+05:30"); + QVERIFY(tztz2.isValid()); + QVERIFY(tzutc2.isValid()); + QTzTimeZonePrivate::Data datatz2 = tztz2.data(std); + QTzTimeZonePrivate::Data datautc2 = tzutc2.data(std); + QCOMPARE(datatz2.offsetFromUtc, datautc2.offsetFromUtc); #endif // Q_OS_UNIX } |