diff options
author | Mitch Curtis <mitch.curtis@digia.com> | 2013-02-04 17:08:24 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-02-12 07:29:36 +0100 |
commit | 4aa86461ebdc9e949ba5ca4b3c41deeb87536475 (patch) | |
tree | 90fd6db50ce14f38afd186c1d53cb9750a190d75 /src | |
parent | 86115848b55faa747adf8bb39a213b3cec7673c4 (diff) |
Ensure QDateTime can handle QDate's full range of julian dates.
Currently, using QDate::maxJd() in tests will fail. This patch changes
some ints to qint64s to prevent overflows where necessary.
Change-Id: I61ebf8f233411a7544689fd5bfa9c3abee54e933
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qdatetime.cpp | 10 | ||||
-rw-r--r-- | src/corelib/tools/qdatetime_p.h | 3 |
2 files changed, 8 insertions, 5 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 5d1f8e7855..83db1c3cc9 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -2404,9 +2404,9 @@ uint QDateTime::toTime_t() const (Qt::UTC). On systems that do not support time zones this function will behave as if local time were Qt::UTC. - Note that there are possible values for \a msecs that lie outside the - valid range of QDateTime, both negative and positive. The behavior of - this function is undefined for those values. + Note that passing the minimum of \c qint64 + (\c{std::numeric_limits<qint64>::min()}) to \a msecs will result in + undefined behavior. \sa toMSecsSinceEpoch(), setTime_t() */ @@ -4010,7 +4010,7 @@ static QDateTimePrivate::Spec utcToLocal(QDate &date, QTime &time) time = QTime(); return QDateTimePrivate::LocalUnknown; } else { - int deltaDays = fakeDate.daysTo(date); + qint64 deltaDays = fakeDate.daysTo(date); date = QDate(brokenDown->tm_year + 1900, brokenDown->tm_mon + 1, brokenDown->tm_mday); time = QTime(brokenDown->tm_hour, brokenDown->tm_min, brokenDown->tm_sec, time.msec()); date = date.addDays(deltaDays); @@ -4078,7 +4078,7 @@ static void localToUtc(QDate &date, QTime &time, int isdst) date = QDate(1970, 1, 1); time = QTime(); } else { - int deltaDays = fakeDate.daysTo(date); + qint64 deltaDays = fakeDate.daysTo(date); date = QDate(brokenDown->tm_year + 1900, brokenDown->tm_mon + 1, brokenDown->tm_mday); time = QTime(brokenDown->tm_hour, brokenDown->tm_min, brokenDown->tm_sec, time.msec()); date = date.addDays(deltaDays); diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h index 4f61e34bf9..c70571d509 100644 --- a/src/corelib/tools/qdatetime_p.h +++ b/src/corelib/tools/qdatetime_p.h @@ -101,6 +101,9 @@ public: void getUTC(QDate &outDate, QTime &outTime) const; static QDateTime addMSecs(const QDateTime &dt, qint64 msecs); static void addMSecs(QDate &utcDate, QTime &utcTime, qint64 msecs); + + static inline qint64 minJd() { return QDate::minJd(); } + static inline qint64 maxJd() { return QDate::maxJd(); } }; #ifndef QT_BOOTSTRAPPED |