diff options
Diffstat (limited to 'src/corelib/tools/qdatetime_p.h')
-rw-r--r-- | src/corelib/tools/qdatetime_p.h | 70 |
1 files changed, 29 insertions, 41 deletions
diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h index 104cbccbd4..c4d00c99f9 100644 --- a/src/corelib/tools/qdatetime_p.h +++ b/src/corelib/tools/qdatetime_p.h @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2016 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -60,9 +61,13 @@ QT_BEGIN_NAMESPACE -class QDateTimePrivate : public QSharedData +class QDateTimePrivate { public: + // forward the declarations from QDateTime (this makes them public) + typedef QDateTime::ShortData QDateTimeShortData; + typedef QDateTime::Data QDateTimeData; + // Never change or delete this enum, it is required for backwards compatible // serialization of QDateTime before 5.2, so is essentially public API enum Spec { @@ -76,7 +81,6 @@ public: // Daylight Time Status enum DaylightStatus { - NoDaylightTime = -2, UnknownDaylightTime = -1, StandardTime = 0, DaylightTime = 1 @@ -84,62 +88,46 @@ public: // Status of date/time enum StatusFlag { - NullDate = 0x01, - NullTime = 0x02, - ValidDate = 0x04, // just the date field - ValidTime = 0x08, // just the time field - ValidDateTime = 0x10, // the whole object (including timezone) + ShortData = 0x01, + + ValidDate = 0x02, + ValidTime = 0x04, + ValidDateTime = 0x08, + + TimeSpecMask = 0x30, + SetToStandardTime = 0x40, SetToDaylightTime = 0x80 }; Q_DECLARE_FLAGS(StatusFlags, StatusFlag) + enum { + TimeSpecShift = 4, + ValidityMask = ValidDate | ValidTime | ValidDateTime, + DaylightMask = SetToStandardTime | SetToDaylightTime + }; + QDateTimePrivate() : m_msecs(0), - m_spec(Qt::LocalTime), + m_status(StatusFlag(Qt::LocalTime << TimeSpecShift)), m_offsetFromUtc(0), - m_status(NullDate | NullTime) - {} + ref(0) + { + } - QDateTimePrivate(const QDate &toDate, const QTime &toTime, Qt::TimeSpec toSpec, - int offsetSeconds); + static QDateTime::Data create(const QDate &toDate, const QTime &toTime, Qt::TimeSpec toSpec, + int offsetSeconds); #ifndef QT_BOOTSTRAPPED - QDateTimePrivate(const QDate &toDate, const QTime &toTime, const QTimeZone & timeZone); + static QDateTime::Data create(const QDate &toDate, const QTime &toTime, const QTimeZone & timeZone); #endif // QT_BOOTSTRAPPED - // ### XXX: when the tooling situation improves, look at fixing the padding. - // 4 bytes padding - qint64 m_msecs; - Qt::TimeSpec m_spec; + StatusFlags m_status; int m_offsetFromUtc; + mutable QAtomicInt ref; #ifndef QT_BOOTSTRAPPED QTimeZone m_timeZone; #endif // QT_BOOTSTRAPPED - StatusFlags m_status; - - void setTimeSpec(Qt::TimeSpec spec, int offsetSeconds); - void setDateTime(const QDate &date, const QTime &time); - QPair<QDate, QTime> getDateTime() const; - - void setDaylightStatus(DaylightStatus status); - DaylightStatus daylightStatus() const; - - // Returns msecs since epoch, assumes offset value is current - inline qint64 toMSecsSinceEpoch() const; - - void checkValidDateTime(); - void refreshDateTime(); - - // Get/set date and time status - inline bool isNullDate() const { return m_status & NullDate; } - inline bool isNullTime() const { return m_status & NullTime; } - inline bool isValidDate() const { return m_status & ValidDate; } - inline bool isValidTime() const { return m_status & ValidTime; } - inline bool isValidDateTime() const { return m_status & ValidDateTime; } - inline void setValidDateTime() { m_status |= ValidDateTime; } - inline void clearValidDateTime() { m_status &= ~ValidDateTime; } - inline void clearSetToDaylightStatus() { m_status &= ~(SetToStandardTime | SetToDaylightTime); } #ifndef QT_BOOTSTRAPPED static qint64 zoneMSecsToEpochMSecs(qint64 msecs, const QTimeZone &zone, |