diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2016-11-21 18:17:07 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2016-12-14 16:40:42 +0000 |
commit | 7c33c644d399e7d547ccf9f779197208d07bca84 (patch) | |
tree | de04e8d639b246c57667d6b7b6a259e7044c8e18 /tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp | |
parent | 9d8db91ada0ab340ae781862f567c9b104e83c63 (diff) |
Fix QDateTime::toString(Qt::ISODate)'s handling of Qt::TimeZone
When the time is specified relative to a zone, the ISO date produced
lacked its offset suffix; all zones were treated as if they were local
time. Handle zone as for an offset from UTC and ensure we do set the
date-time objects's offset from UTC when it's zone-based.
Change-Id: I7c9896bb8ec0a9d89df14a6e94b005174ab9e943
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp')
-rw-r--r-- | tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index d4ae1b2a91..a5efbb9950 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -77,6 +77,7 @@ private slots: void fromMSecsSinceEpoch(); void toString_isoDate_data(); void toString_isoDate(); + void toString_isoDate_extra(); void toString_textDate_data(); void toString_textDate(); void toString_rfcDate_data(); @@ -794,6 +795,28 @@ void tst_QDateTime::toString_isoDate() QLocale::setDefault(oldLocale); } +void tst_QDateTime::toString_isoDate_extra() +{ + QDateTime dt = QDateTime::fromMSecsSinceEpoch(0, Qt::UTC); + QCOMPARE(dt.toString(Qt::ISODate), QLatin1String("1970-01-01T00:00:00Z")); +#if QT_CONFIG(timezone) + QTimeZone PST("America/Vancouver"); + if (PST.isValid()) { + dt = QDateTime::fromMSecsSinceEpoch(0, PST); + QCOMPARE(dt.toString(Qt::ISODate), QLatin1String("1969-12-31T16:00:00-08:00")); + } else { + qDebug("Missed zone test: no America/Vancouver zone available"); + } + QTimeZone CET("Europe/Berlin"); + if (CET.isValid()) { + dt = QDateTime::fromMSecsSinceEpoch(0, CET); + QCOMPARE(dt.toString(Qt::ISODate), QLatin1String("1970-01-01T01:00:00+01:00")); + } else { + qDebug("Missed zone test: no Europe/Berlin zone available"); + } +#endif // timezone +} + void tst_QDateTime::toString_textDate_data() { QTest::addColumn<QDateTime>("datetime"); |