From 13c16bbd06e0034210ba2164f1be208c49a6e3a7 Mon Sep 17 00:00:00 2001 From: John Layt Date: Mon, 25 Feb 2013 13:36:29 +0000 Subject: QDateTime - Improve and expose Qt::OffsetFromUtc The Qt::OffsetFromUtc TimeSpec was made public in Qt 4.4 but the access methods were never made public in the apidox effectively meaning the feature was never used. The implementation was also incomplete and inconsistent. This change cleans up the implementation and exports new public API for using the TimeSpec using new method names consistent with the new QTimeZone support. This change increases the QDataStream Version number for Qt 5.2 to 15. The behavior of one constructor has changed slightly to be consistent with the rest of the feature, but this behavior was never documented. [ChangeLog][QtCore][QDateTime] Fully implement support for Qt::TimeSpec of Qt::OffsetFromUTC, added new methods for offsetFromUTC(), toTimeSpec(), and toOffsetFromUTC(). Task-number: QTBUG-26161 Task-number: QTBUG-29666 Change-Id: If3cc7fc9778ca2b831644408ae749448d5975a3a Reviewed-by: Thiago Macieira Reviewed-by: Mitch Curtis --- src/corelib/tools/qdatetime_p.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/corelib/tools/qdatetime_p.h') diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h index c70571d509..f3abcf02d8 100644 --- a/src/corelib/tools/qdatetime_p.h +++ b/src/corelib/tools/qdatetime_p.h @@ -81,25 +81,27 @@ class QDateTimePrivate : public QSharedData public: enum Spec { LocalUnknown = -1, LocalStandard = 0, LocalDST = 1, UTC = 2, OffsetFromUTC = 3}; - QDateTimePrivate() : spec(LocalUnknown), utcOffset(0) {} + QDateTimePrivate() : spec(LocalUnknown), m_offsetFromUtc(0) {} + QDateTimePrivate(const QDate &toDate, const QTime &toTime, Qt::TimeSpec toSpec, + int offsetSeconds); QDateTimePrivate(const QDateTimePrivate &other) - : QSharedData(other), date(other.date), time(other.time), spec(other.spec), utcOffset(other.utcOffset) + : QSharedData(other), date(other.date), time(other.time), spec(other.spec), + m_offsetFromUtc(other.m_offsetFromUtc) {} QDate date; QTime time; Spec spec; - /*! - \internal - \since 4.4 - - The offset in seconds. Applies only when timeSpec() is OffsetFromUTC. - */ - int utcOffset; + int m_offsetFromUtc; + // Get current date/time in LocalTime and put result in outDate and outTime Spec getLocal(QDate &outDate, QTime &outTime) const; + // Get current date/time in UTC and put result in outDate and outTime void getUTC(QDate &outDate, QTime &outTime) const; + + // Add msecs to given datetime and return result static QDateTime addMSecs(const QDateTime &dt, qint64 msecs); + // Add msecs to given datetime and put result in utcDate and utcTime static void addMSecs(QDate &utcDate, QTime &utcTime, qint64 msecs); static inline qint64 minJd() { return QDate::minJd(); } -- cgit v1.2.3