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>
This commit is contained in:
parent
9072edb5f7
commit
5c67ce5d6d
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user