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 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 }