From f881120fd0e2496618c8587d091178f3d2f0b294 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 27 Mar 2017 11:12:01 +0200 Subject: Fix offset calculation to be valid at the correct time tst_QLocale::macDefaultLocale() was determining local-time's current offset from UTC and using it when working out what to expect the offset at 1:2:3 today to be. When a transition happens after 1:2:3 on its day (which is usual for DST changes in Europe), this lead to using the new offset to test a time before the transition; the test was thus wrong and failed. Use the time to be tested (and current date) to compute the offset to use, instead of using the current date-time. Change-Id: I1c02a5579bca859e1d1aeb4f45b24871a08287af Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qlocale/tst_qlocale.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'tests/auto/corelib/tools/qlocale/tst_qlocale.cpp') diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index 5d13d9e454..9e5118f9ce 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -1584,10 +1584,9 @@ void tst_QLocale::macDefaultLocale() // make sure we are using the system to parse them QCOMPARE(locale.toString(1234.56), systemLocaleFormatNumber(QString("1,234.56"))); - QTime currentTime = QTime::currentTime(); - QTime utcTime = QDateTime::currentDateTime().toUTC().time(); - - int diff = currentTime.hour() - utcTime.hour(); + QTime testTime = QTime(1, 2, 3); + QTime utcTime = QDateTime(QDate::currentDate(), testTime).toUTC().time(); + int diff = testTime.hour() - utcTime.hour(); // Check if local time and utc time are on opposite sides of the 24-hour wrap-around. if (diff < -12) @@ -1595,7 +1594,7 @@ void tst_QLocale::macDefaultLocale() if (diff > 12) diff -= 24; - const QString timeString = locale.toString(QTime(1,2,3), QLocale::LongFormat); + const QString timeString = locale.toString(testTime, QLocale::LongFormat); QVERIFY(timeString.contains(QString("1:02:03"))); // To run this test make sure "Curreny" is US Dollar in System Preferences->Language & Region->Advanced. -- cgit v1.2.3