diff options
author | Matthew Vogt <matthew.vogt@nokia.com> | 2012-04-23 15:14:42 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-24 00:33:25 +0200 |
commit | 5dac3d9f846d0a9cffb95608219fefd4079a7bc2 (patch) | |
tree | af71dea03eb2fd7c46e3e584380e7007d2a78eea /tests/auto/qml/qqmlecmascript/testtypes.h | |
parent | a8e017fbc22d8ec445fc9202479a775bdac4d5b0 (diff) |
Verify that QML can reliably receive datetime info from C++
Since a JavaScript Date object does not contain any information about
the timezone in which it is specified, a C++ module that exports
datetime information to QML must also provide the relevant timezone
data so that clients can correctly interpret the datetime value.
Provide an example of exporting datetime information to QML, verifying
that the data can be correctly interpreted in JS.
Task-number: QTBUG-25262
Change-Id: I732797da225861470e6b034f2e3d89a43df36cf7
Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/testtypes.h')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/testtypes.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index b0d7e0f723..502c65db38 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -1332,6 +1332,43 @@ private: MyQmlObject *m_nestedObject; }; +class DateTimeExporter : public QObject +{ + Q_OBJECT + +public: + DateTimeExporter(const QDateTime &dt) : m_datetime(dt), m_offset(0), m_timespec("UTC") + { + switch (m_datetime.timeSpec()) { + case Qt::LocalTime: + { + QDateTime utc(m_datetime.toUTC()); + utc.setTimeSpec(Qt::LocalTime); + m_offset = m_datetime.secsTo(utc) / 60; + m_timespec = "LocalTime"; + } + break; + case Qt::OffsetFromUTC: + m_offset = m_datetime.utcOffset() / 60; + m_timespec = QString("%1%2:%3").arg(m_offset < 0 ? '-' : '+') + .arg(abs(m_offset) / 60) + .arg(abs(m_offset) % 60); + default: + break; + } + } + + Q_INVOKABLE QDate getDate() const { return m_datetime.date(); } + Q_INVOKABLE QDateTime getDateTime() const { return m_datetime; } + Q_INVOKABLE int getDateTimeOffset() const { return m_offset; } + Q_INVOKABLE QString getTimeSpec() const { return m_timespec; } + +private: + QDateTime m_datetime; + int m_offset; + QString m_timespec; +}; + void registerTypes(); #endif // TESTTYPES_H |