summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2017-03-27 11:12:01 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2017-07-03 09:03:28 +0000
commitf881120fd0e2496618c8587d091178f3d2f0b294 (patch)
tree65df3b7434dd0ac86363855958c7146aadd6611d /tests/auto
parentd52fa3efe5bdb5440a4d916df796fd9bba246110 (diff)
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 <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/tools/qlocale/tst_qlocale.cpp9
1 files changed, 4 insertions, 5 deletions
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.