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>
This commit is contained in:
parent
c8b0c428d2
commit
6be9cb2068
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user