From: Mitch Curtis Date: Mon, 6 Aug 2012 10:08:42 +0000 (+0200) Subject: Clarify how days are counted in QDateTime::daysTo documentation. X-Git-Tag: v5.0.0-beta1~370 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ebbd8e66717e7bf400b395e240569e72409c9959;p=profile%2Fivi%2Fqtbase.git Clarify how days are counted in QDateTime::daysTo documentation. Mention that the days are counted as the amount of times midnight is reached between the start and end date. Task-number: QTBUG-26780 Change-Id: I22ff6c56b748ac968d6991e0be3e10905c0634bd Reviewed-by: Thiago Macieira --- diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp index 59cd67f..ce0ccc1 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp @@ -144,3 +144,16 @@ QDateTime dateTime = QDateTime::fromString("130", "Mm"); // invalid QDateTime dateTime = QDateTime::fromString("1.30.1", "M.d.s"); // dateTime is January 30 in 1900 at 00:00:01. //! [14] + +//! [15] +QDateTime startDate(QDate(2012, 7, 6), QTime(8, 30, 0)); +QDateTime endDate(QDate(2012, 7, 7), QTime(16, 30, 0)); +qDebug() << "Days from startDate to endDate: " << startDate.daysTo(endDate); + +startDate = QDateTime(QDate(2012, 7, 6), QTime(23, 55, 0)); +endDate = QDateTime(QDate(2012, 7, 7), QTime(0, 5, 0)); +qDebug() << "Days from startDate to endDate: " << startDate.daysTo(endDate); + +qSwap(startDate, endDate); // Make endDate before startDate. +qDebug() << "Days from startDate to endDate: " << startDate.daysTo(endDate); +//! [15] \ No newline at end of file diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 87ff03c..769ab0a 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -2765,9 +2765,17 @@ QDateTime QDateTime::addMSecs(qint64 msecs) const /*! Returns the number of days from this datetime to the \a other - datetime. If the \a other datetime is earlier than this datetime, + datetime. The number of days is counted as the number of times + midnight is reached between this datetime to the \a other + datetime. This means that a 10 minute difference from 23:55 to + 0:05 the next day counts as one day. + + If the \a other datetime is earlier than this datetime, the value returned is negative. + Example: + \snippet code/src_corelib_tools_qdatetime.cpp 15 + \sa addDays(), secsTo(), msecsTo() */