summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJohn Layt <jlayt@kde.org>2013-10-15 17:36:36 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-16 21:29:17 +0200
commit6a63554bf8226b4ffcf23e45627e6e7920671fac (patch)
tree94bea1f54c2d658041da2b35883c6234d119a420 /tests
parent24b817f20a7956470971b64436f6b8f1f9745115 (diff)
QDateTime - Fix toTimeSpec() for invalid datetimes
Check if the datetime is valid before converting it to a different time spec. If it is invalid then just change the spec to keep behavior consistent with 5.1. Task-number: QTBUG-34020 Change-Id: I6630ec1d50f810a2178ab3222bd32af018085f81 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
index b8b970121c..0c560df423 100644
--- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
@@ -147,6 +147,8 @@ private slots:
void daylightTransitions() const;
void timeZones() const;
+ void invalid() const;
+
private:
bool europeanTimeZone;
QDate defDate() const { return QDate(1900, 1, 1); }
@@ -2899,5 +2901,24 @@ void tst_QDateTime::timeZones() const
QCOMPARE(hourAfterStd.toMSecsSinceEpoch(), dstToStdMSecs + 3600000);
}
+void tst_QDateTime::invalid() const
+{
+ QDateTime invalidDate = QDateTime(QDate(0, 0, 0), QTime(-1, -1, -1));
+ QCOMPARE(invalidDate.isValid(), false);
+ QCOMPARE(invalidDate.timeSpec(), Qt::LocalTime);
+
+ QDateTime utcDate = invalidDate.toUTC();
+ QCOMPARE(utcDate.isValid(), false);
+ QCOMPARE(utcDate.timeSpec(), Qt::UTC);
+
+ QDateTime offsetDate = invalidDate.toOffsetFromUtc(3600);
+ QCOMPARE(offsetDate.isValid(), false);
+ QCOMPARE(offsetDate.timeSpec(), Qt::OffsetFromUTC);
+
+ QDateTime tzDate = invalidDate.toTimeZone(QTimeZone("Europe/Oslo"));
+ QCOMPARE(tzDate.isValid(), false);
+ QCOMPARE(tzDate.timeSpec(), Qt::TimeZone);
+}
+
QTEST_APPLESS_MAIN(tst_QDateTime)
#include "tst_qdatetime.moc"