aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/jsruntime/qv4dateobject.cpp21
-rw-r--r--tests/auto/qml/qqmllocale/tst_qqmllocale.cpp16
2 files changed, 35 insertions, 2 deletions
diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp
index bebcbd7e44..4e445a73fa 100644
--- a/src/qml/jsruntime/qv4dateobject.cpp
+++ b/src/qml/jsruntime/qv4dateobject.cpp
@@ -54,11 +54,28 @@
#include <wtf/MathExtras.h>
-#if defined(Q_OS_LINUX) && QT_CONFIG(timezone) && !defined(Q_OS_ANDROID)
+#if QT_CONFIG(timezone) && !defined(Q_OS_WIN)
/*
See QTBUG-56899. Although we don't (yet) have a proper way to reset the
system zone, the code below, that uses QTimeZone::systemTimeZone(), works
- adequately on Linux, when the TZ environment variable is changed.
+ adequately on Linux.
+
+ QTimeZone::systemTimeZone() will automatically produce an updated value on
+ non-android Linux systems when the TZ environment variable or the relevant
+ files in /etc are changed. On other platforms it won't, and the information
+ produced here may be incorrect after changes to the system time zone.
+
+ We accept this defect for now because the localtime_r approach will
+ consistently produce incorrect results for some time zones, not only when
+ the system time zone changes. This is a worse problem, see also QTBUG-84474.
+
+ On windows we have a better implementation of getLocalTZA that hopefully
+ updates on time zone changes. However, we currently use the worse
+ implementation of DaylightSavingTA (returning either an hour or 0).
+
+ QTimeZone::systemTimeZone() on Linux is also slower than other approaches
+ because it has to poll the relevant files (if TZ is not set). See
+ QTBUG-75585 for an explanation and possible workarounds.
*/
#define USE_QTZ_SYSTEM_ZONE
#endif
diff --git a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp
index e3094db708..7d0c10a702 100644
--- a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp
+++ b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp
@@ -34,6 +34,7 @@
#include <QtCore/QDateTime>
#include <QtCore/qscopeguard.h>
#include <QtCore/qscopedpointer.h>
+#include <QtCore/qtimezone.h>
#include <qcolor.h>
#include "../../shared/util.h"
@@ -1297,6 +1298,13 @@ static void setTimeZone(const QByteArray &tz)
void tst_qqmllocale::timeZoneUpdated()
{
+ // Note: This test may not reliably hit the QEXPECT_FAIL clauses below if the initial
+ // system time zone is equivalent to either Australia/Brisbane or Asia/Kalkota.
+
+ // Initialize the system time zone, so that we actually _change_ something below.
+ QVERIFY2(QTimeZone::systemTimeZone().isValid(),
+ "You know, Toto, I do believe we're not in Kansas any more.");
+
QByteArray original(qgetenv("TZ"));
// Set the timezone to Brisbane time, AEST-10:00
@@ -1318,12 +1326,20 @@ void tst_qqmllocale::timeZoneUpdated()
QVERIFY2(!c.isError(), qPrintable(c.errorString()));
obj.reset(c.create());
QVERIFY(obj);
+
+#if !defined(Q_OS_WIN) && QT_CONFIG(timezone) && (!defined(Q_OS_LINUX) || defined(Q_OS_ANDROID))
+ QEXPECT_FAIL("", "Date.timeZoneUpdated() only works on non-Android Linux with QT_CONFIG(timezone).", Continue);
+#endif
QVERIFY(obj->property("success").toBool());
// Change to Indian time, IST-05:30
setTimeZone(QByteArray("Asia/Kolkata"));
QMetaObject::invokeMethod(obj.data(), "check");
+
+#if !defined(Q_OS_WIN) && QT_CONFIG(timezone) && (!defined(Q_OS_LINUX) || defined(Q_OS_ANDROID))
+ QEXPECT_FAIL("", "Date.timeZoneUpdated() only works on non-Android Linux with QT_CONFIG(timezone).", Continue);
+#endif
QVERIFY(obj->property("success").toBool());
}
#endif