From kde-core-devel Sun Oct 07 20:23:56 2012 From: Jon Severinsson Date: Sun, 07 Oct 2012 20:23:56 +0000 To: kde-core-devel Subject: =?UTF-8?q?=5BPATCH=5D=20kdecore=3A=20Fix=20a=20bug=20in=20KDateTime=20utc=20offset=20string=20parsin Message-Id: <1349641436-2134-1-git-send-email-jon () severinsson ! net> X-MARC-Message: https://marc.info/?l=kde-core-devel&m=134967678503564 The sign of the UTC offset was ignored, and an offset of -0500 (New York) would be treated at +0500 (Pakistan). This commit also adds a unit test for UTC offset parsing and comparasion. --- Hi When mucking around in the frameworks branch of kdelibs I found a bug in the KDateTime string parsing, which appears to be present in master as well as every branch from 4.0 to 4.10. I have, however, only run the updated unittest using the frameworks branch and Qt5, so someone else should probably test on 4.9, 4.10 and/or master before committing it. Best Regards Jon Severinsson kdecore/date/kdatetime.cpp | 2 +- kdecore/tests/kdatetimetest.cpp | 7 +++++++ 2 filer ändrade, 8 tillägg(+), 1 borttagning(-) diff --git a/kdecore/date/kdatetime.cpp b/kdecore/date/kdatetime.cpp index d4f63ff..df1fc3d 100644 --- a/kdecore/date/kdatetime.cpp +++ b/kdecore/date/kdatetime.cpp @@ -2962,7 +2962,7 @@ bool getUTCOffset(const QString &string, int &offset, bool colon, int &result) tzmin += tzhour * 60; if (result != NO_NUMBER && result != tzmin) return false; - result = tzmin; + result = sign * tzmin; return true; } diff --git a/kdecore/tests/kdatetimetest.cpp b/kdecore/tests/kdatetimetest.cpp index e79e9f2..812abc5 100644 --- a/kdecore/tests/kdatetimetest.cpp +++ b/kdecore/tests/kdatetimetest.cpp @@ -3807,6 +3807,13 @@ void KDateTimeTest::strings_format() QVERIFY(!dt.isValid()); // too early QVERIFY(dt.outOfRange()); + dtutc = KDateTime::fromString(QLatin1String("2000-01-01T00:00:00.000+0000"), QLatin1String("%Y-%m-%dT%H:%M%:S%:s%z")); + QVERIFY(dtutc.isValid()); + dt = KDateTime::fromString(QLatin1String("2000-01-01T05:00:00.000+0500"), QLatin1String("%Y-%m-%dT%H:%M%:S%:s%z")); + QVERIFY(dt.isValid()); + QVERIFY(dtutc == dt); + dt = KDateTime::fromString(QLatin1String("1999-12-31T20:30:00.000-0330"), QLatin1String("%Y-%m-%dT%H:%M%:S%:s%z")); + QVERIFY(dtutc == dt); // Restore the original local time zone if (originalZone.isEmpty()) -- 1.7.10.4