Change QDateTime::addSecs() and QDateTime::secsTo() to use qint64.

addMSecs() / msecsTo() have always used qint64, and when QDate was changed
to use a 64-bit julian day, QDateTime::addDays() and QDateTime::daysTo() was
changed to use qint64 in order to support the full extended range, but
addSecs() and secsTo() seems to have been forgotten.

Change-Id: I3acc35ee2bcc9f353650eb42f97d428f706b2db6
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Jon Severinsson 2012-10-09 15:15:53 +02:00 committed by The Qt Project
parent 78dddc2802
commit 85c47eed6b
3 changed files with 7 additions and 7 deletions

View File

@ -2756,9 +2756,9 @@ void QDateTimePrivate::addMSecs(QDate &utcDate, QTime &utcTime, qint64 msecs)
\sa addMSecs(), secsTo(), addDays(), addMonths(), addYears()
*/
QDateTime QDateTime::addSecs(int s) const
QDateTime QDateTime::addSecs(qint64 s) const
{
return d->addMSecs(*this, qint64(s) * 1000);
return d->addMSecs(*this, s * 1000);
}
/*!
@ -2811,7 +2811,7 @@ qint64 QDateTime::daysTo(const QDateTime &other) const
\sa addSecs(), daysTo(), QTime::secsTo()
*/
int QDateTime::secsTo(const QDateTime &other) const
qint64 QDateTime::secsTo(const QDateTime &other) const
{
if (!isValid() || !other.isValid())
return 0;

View File

@ -232,13 +232,13 @@ public:
QDateTime addDays(qint64 days) const;
QDateTime addMonths(int months) const;
QDateTime addYears(int years) const;
QDateTime addSecs(int secs) const;
QDateTime addSecs(qint64 secs) const;
QDateTime addMSecs(qint64 msecs) const;
QDateTime toTimeSpec(Qt::TimeSpec spec) const;
inline QDateTime toLocalTime() const { return toTimeSpec(Qt::LocalTime); }
inline QDateTime toUTC() const { return toTimeSpec(Qt::UTC); }
qint64 daysTo(const QDateTime &) const;
int secsTo(const QDateTime &) const;
qint64 secsTo(const QDateTime &) const;
qint64 msecsTo(const QDateTime &) const;
bool operator==(const QDateTime &other) const;

View File

@ -916,8 +916,8 @@ void tst_QDateTime::secsTo()
#ifdef Q_OS_IRIX
QEXPECT_FAIL("cet4", "IRIX databases say 1970 had DST", Abort);
#endif
QCOMPARE(dt.secsTo(result), nsecs);
QCOMPARE(result.secsTo(dt), -nsecs);
QCOMPARE(dt.secsTo(result), (qint64)nsecs);
QCOMPARE(result.secsTo(dt), (qint64)-nsecs);
QVERIFY((dt == result) == (0 == nsecs));
QVERIFY((dt != result) == (0 != nsecs));
QVERIFY((dt < result) == (0 < nsecs));