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>
This commit is contained in:
Edward Welbourne 2017-03-27 11:12:01 +02:00
parent d52fa3efe5
commit f881120fd0

View File

@ -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.