diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-01-10 18:27:48 +0100 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-01-10 18:27:49 +0100 |
commit | 7917dfbf1c54150d0ca3a79285767c22e6f9d770 (patch) | |
tree | a05973334097df480afe32d07db42f381b460e74 /tests/auto/corelib/tools/qdatetime | |
parent | b9362903b339e57362a7a3296904504521d0e26f (diff) | |
parent | b088e4827f427189334e8a1c5b4f2b8b0b713fc2 (diff) |
Merge remote-tracking branch 'origin/stable' into dev
Change-Id: I99af0bef7f1c931533a324ebcfb27c40ee871a5e
Diffstat (limited to 'tests/auto/corelib/tools/qdatetime')
-rw-r--r-- | tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index 7d51696fe3..0e7ac54a86 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -64,6 +64,7 @@ public: static QString str( int y, int month, int d, int h, int min, int s ); static QDateTime dt( const QString& str ); public slots: + void initTestCase(); void init(); private slots: void ctor(); @@ -153,6 +154,7 @@ private slots: void invalid() const; private: + enum { LocalTimeIsUtc = 0, LocalTimeAheadOfUtc = 1, LocalTimeBehindUtc = -1} localTimeType; bool europeanTimeZone; QDate defDate() const { return QDate(1900, 1, 1); } QTime defTime() const { return QTime(0, 0, 0); } @@ -172,6 +174,42 @@ tst_QDateTime::tst_QDateTime() uint x1 = QDateTime(QDate(1990, 1, 1), QTime()).toTime_t(); uint x2 = QDateTime(QDate(1990, 6, 1), QTime()).toTime_t(); europeanTimeZone = (x1 == 631148400 && x2 == 644191200); + + QDateTime dt1 = QDateTime::fromTime_t(0); + QDateTime dt2 = QDateTime::fromTime_t(181 * 86400); // six months later, Jul 1 + if (dt1.date().year() < 1970 || dt2.date().month() < 7) { + localTimeType = LocalTimeBehindUtc; + } else if (dt1.time().hour() > 0 || dt1.date().day() > 1) { + localTimeType = LocalTimeAheadOfUtc; + } else if (dt2.time().hour() > 0 || dt2.date().day() > 1) { + localTimeType = LocalTimeAheadOfUtc; + } else { + localTimeType = LocalTimeIsUtc; + } +} + +void tst_QDateTime::initTestCase() +{ + // Never construct a message like this in an i18n context... + const char *typemsg1, *typemsg2 = "and therefore not"; + switch (localTimeType) { + case LocalTimeIsUtc: + typemsg1 = "exactly"; + break; + case LocalTimeBehindUtc: + typemsg1 = "behind"; + break; + case LocalTimeAheadOfUtc: + typemsg1 = "ahead of"; + typemsg2 = europeanTimeZone ? "and is" : "but isn't"; + break; + } + + qDebug() << "Current local time detected to be" + << typemsg1 + << "UTC" + << typemsg2 + << "the Central European timezone"; } void tst_QDateTime::init() @@ -613,8 +651,10 @@ void tst_QDateTime::fromMSecsSinceEpoch() QDateTime dtUtc = QDateTime::fromMSecsSinceEpoch(msecs, Qt::UTC); QDateTime dtOffset = QDateTime::fromMSecsSinceEpoch(msecs, Qt::OffsetFromUTC, 60*60); - // LocalTime will overflow for max - if (msecs != std::numeric_limits<qint64>::max()) + // LocalTime will overflow for min or max, depending on whether you're + // East or West of Greenwich. The test passes at GMT. + if (localTimeType == LocalTimeIsUtc + || msecs != std::numeric_limits<qint64>::max() * localTimeType) QCOMPARE(dtLocal, utc); QCOMPARE(dtUtc, utc); |