summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2013-12-13 15:34:29 -0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-09 22:49:23 +0100
commiteaedc04d90fdfc28cc9de96a32635bf327769086 (patch)
treeb0f77d7942556ccfc71d1d26f221166e9437eec6
parentc8a8e0fb18c7c7cb6cf445dc9595eaf69f3cd126 (diff)
downloadqtbase-eaedc04d90fdfc28cc9de96a32635bf327769086.tar.gz
qtbase-eaedc04d90fdfc28cc9de96a32635bf327769086.tar.bz2
qtbase-eaedc04d90fdfc28cc9de96a32635bf327769086.zip
Autotest: Fix QDateTime failure if the test got run West of Greenwich
There was a comment about the test failing for max() because of an overflow. That happens if you're at UTC or ahead of it (to the East of the Prime Meridian), which is how this test usually gets run (UTC, Europe/Oslo, Europe/Helsinki, Pacific/Auckland). But if you're behind UTC (to the West of the Prime Meridian), then the overflow happens for min(). Change-Id: Iebba49d1303e9f18f5038f5cf23c77bf83e5fd4b Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp44
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 6c80c5ff47..5d1fe0784f 100644
--- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
@@ -61,6 +61,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();
@@ -150,6 +151,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); }
@@ -169,6 +171,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()
@@ -610,8 +648,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);