aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmllocale
diff options
context:
space:
mode:
authorMatthew Vogt <matthew.vogt@nokia.com>2012-06-04 15:32:32 +1000
committerQt by Nokia <qt-info@nokia.com>2012-06-05 04:35:50 +0200
commit2d1fc405b4048560a6f80add6ee6492fa934c91f (patch)
tree61088efa7a2e75092562e169f2ac14df7be599bd /tests/auto/qml/qqmllocale
parent805c30e809a86cc1feabeb3bdbee943a7bbf8796 (diff)
Allow the global JS UTC offset to be invalidated
If the system timezone is changed, it is necessary to inform V8 so that the global offset-from-UTC value can be recalculated. This changes adds the 'timeZoneUpdated' function to the JS 'Date' class exported by QML, which allows QML applications to inform V8 when the timezone has been updated. Change-Id: Ic5898ca7bc640002a4a6fd5a52b8623d87ee8085 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests/auto/qml/qqmllocale')
-rw-r--r--tests/auto/qml/qqmllocale/data/timeZoneUpdated.qml51
-rw-r--r--tests/auto/qml/qqmllocale/tst_qqmllocale.cpp41
2 files changed, 92 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllocale/data/timeZoneUpdated.qml b/tests/auto/qml/qqmllocale/data/timeZoneUpdated.qml
new file mode 100644
index 0000000000..92d1f5bc40
--- /dev/null
+++ b/tests/auto/qml/qqmllocale/data/timeZoneUpdated.qml
@@ -0,0 +1,51 @@
+import QtQuick 2.0
+
+Item {
+ property bool success: false
+
+ property date localDate
+ property date utcDate
+
+ Component.onCompleted: {
+ // Test date: 2012-06-01T02:15:30+10:00 (AEST timezone)
+ localDate = new Date(2012, 6-1, 1, 2, 15, 30)
+ utcDate = new Date(Date.UTC(2012, 6-1, 1, 2, 15, 30))
+
+ if (localDate.getTimezoneOffset() != -600) return
+
+ if (localDate.toLocaleString() != "Friday, June 1, 2012 2:15:30 AM AEST") return
+ if (localDate.toISOString() != "2012-05-31T16:15:30.000Z") return
+
+ if (utcDate.toISOString() != "2012-06-01T02:15:30.000Z") return
+ if (utcDate.toLocaleString() != "Friday, June 1, 2012 12:15:30 PM AEST") return
+
+ success = true
+ }
+
+ function check() {
+ success = false
+
+ // We have changed to IST time zone - inform JS:
+ Date.timeZoneUpdated()
+
+ if (localDate.getTimezoneOffset() != -330) return
+
+ if (localDate.toLocaleString() != "Friday, June 1, 2012 2:15:30 AM IST") return
+ if (localDate.toISOString() != "2012-05-31T20:45:30.000Z") return
+
+ if (utcDate.toISOString() != "2012-06-01T06:45:30.000Z") return
+ if (utcDate.toLocaleString() != "Friday, June 1, 2012 12:15:30 PM IST") return
+
+ // Create new dates in this timezone
+ localDate = new Date(2012, 6-1, 1, 2, 15, 30)
+ utcDate = new Date(Date.UTC(2012, 6-1, 1, 2, 15, 30))
+
+ if (localDate.toLocaleString() != "Friday, June 1, 2012 2:15:30 AM IST") return
+ if (localDate.toISOString() != "2012-05-31T20:45:30.000Z") return
+
+ if (utcDate.toISOString() != "2012-06-01T02:15:30.000Z") return
+ if (utcDate.toLocaleString() != "Friday, June 1, 2012 7:45:30 AM IST") return
+
+ success = true
+ }
+}
diff --git a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp
index e74570261f..c39426375f 100644
--- a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp
+++ b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp
@@ -47,6 +47,8 @@
#include <qcolor.h>
#include "../../shared/util.h"
+#include <time.h>
+
class tst_qqmllocale : public QQmlDataTest
{
Q_OBJECT
@@ -80,6 +82,7 @@ private slots:
void dateTimeFormat();
void timeFormat_data();
void timeFormat();
+ void timeZoneUpdated();
void dateToLocaleString_data();
void dateToLocaleString();
@@ -1214,6 +1217,44 @@ void tst_qqmllocale::stringLocaleCompare()
QCOMPARE(obj->property("comparison").toInt(), QString::localeAwareCompare(string1, string2));
}
+static void setTimeZone(const QByteArray &tz)
+{
+ qputenv("TZ", tz);
+#if defined(Q_OS_WIN32)
+ ::_tzset();
+#elif defined(Q_OS_UNIX)
+ ::tzset();
+#endif
+}
+
+void tst_qqmllocale::timeZoneUpdated()
+{
+#if !defined(Q_OS_WIN32) && !defined(Q_OS_UINX)
+ QSKIP("Timezone manipulation not available for this platform");
+#endif
+
+ QByteArray original(qgetenv("TZ"));
+
+ // Set the timezone to Brisbane time
+ setTimeZone(QByteArray("AEST-10:00"));
+
+ QQmlEngine e;
+ QQmlComponent c(&e, testFileUrl("timeZoneUpdated.qml"));
+ QScopedPointer<QObject> obj(c.create());
+ QVERIFY(obj);
+ QCOMPARE(obj->property("success").toBool(), true);
+
+ // Change to Indian time
+ setTimeZone(QByteArray("IST-05:30"));
+
+ QMetaObject::invokeMethod(obj.data(), "check");
+
+ // Reset to original time
+ setTimeZone(original);
+
+ QCOMPARE(obj->property("success").toBool(), true);
+}
+
QTEST_MAIN(tst_qqmllocale)
#include "tst_qqmllocale.moc"