summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qdatetime.cpp
diff options
context:
space:
mode:
authorJohn Layt <jlayt@kde.org>2013-08-01 15:51:08 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-21 14:25:07 +0200
commit6be9cb2068fcf21c8957e5aed4c235efc2eb6b2e (patch)
tree8c7c3f7d54cd1192b8f1fbdafd4cdff448f0d4eb /src/corelib/tools/qdatetime.cpp
parentc8b0c428d2b0eaab925f65deee5b5ebe050ecfa6 (diff)
QDateTime - Use the copy constructor in addDays/Months/Years
Currently the QDateTime::addDays/Months/Years methods copy all the d member variables themselves, but this is bad practice as it means 3 more places where we have to get the copy code correct. Instead use the copy constructor to do what it's meant to. This saves more changes when we add proper OffsetFromUTC and TimeZone support. Change-Id: Ie2641d0cb58405335206edcce2e2db30702b78bf Reviewed-by: Mitch Curtis <mitch.curtis@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qdatetime.cpp')
-rw-r--r--src/corelib/tools/qdatetime.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index 7b99aa1e06..b47511c39c 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -2716,7 +2716,10 @@ QString QDateTime::toString(const QString& format) const
QDateTime QDateTime::addDays(qint64 ndays) const
{
- return QDateTime(d->date.addDays(ndays), d->time, timeSpec());
+ QDateTime dt(*this);
+ dt.detach();
+ dt.d->date = d->date.addDays(ndays);
+ return dt;
}
/*!
@@ -2729,7 +2732,10 @@ QDateTime QDateTime::addDays(qint64 ndays) const
QDateTime QDateTime::addMonths(int nmonths) const
{
- return QDateTime(d->date.addMonths(nmonths), d->time, timeSpec());
+ QDateTime dt(*this);
+ dt.detach();
+ dt.d->date = d->date.addMonths(nmonths);
+ return dt;
}
/*!
@@ -2742,7 +2748,10 @@ QDateTime QDateTime::addMonths(int nmonths) const
QDateTime QDateTime::addYears(int nyears) const
{
- return QDateTime(d->date.addYears(nyears), d->time, timeSpec());
+ QDateTime dt(*this);
+ dt.detach();
+ dt.d->date = d->date.addYears(nyears);
+ return dt;
}
QDateTime QDateTimePrivate::addMSecs(const QDateTime &dt, qint64 msecs)