summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorJon Severinsson <jon@severinsson.net>2012-10-09 15:44:42 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-10 08:45:22 +0200
commit4ec79a151f9007d739b0970c062eb452133be4d6 (patch)
treebec2f526dbc7e5415003480dd4059d9759f733d5 /src/corelib
parent85c47eed6b6bfdacfb8e6438b6ef8a1185168675 (diff)
Simplify QDate::addDays() impementation
No need to check for overflows since the change to qint64. as less than half the qint64 range is a valid julian day, any overflow will be detected as an invalid date anyway. Change-Id: I3b6cad24e245ed9418c5804484f846b0b692153a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qdatetime.cpp17
1 files changed, 3 insertions, 14 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index 0e3da78280..cbdd183f33 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -917,20 +917,9 @@ QDate QDate::addDays(qint64 ndays) const
if (isNull())
return QDate();
- QDate d;
- quint64 diff = 0;
-
- // this is basically "d.jd = jd + ndays" with checks for integer overflow
- // Due to limits on minJd() and maxJd() we know diff will never overflow
- if (ndays >= 0)
- diff = maxJd() - jd;
- else
- diff = jd - minJd();
-
- if ((quint64)qAbs(ndays) <= diff)
- d.jd = jd + ndays;
-
- return d;
+ // Due to limits on minJd() and maxJd() we know that any overflow
+ // will be invalid and caught by fromJulianDay().
+ return fromJulianDay(jd + ndays);
}
/*!