diff options
Diffstat (limited to 'src/corelib/tools/qdatetime_p.h')
-rw-r--r-- | src/corelib/tools/qdatetime_p.h | 85 |
1 files changed, 38 insertions, 47 deletions
diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h index 104cbccbd4..eb33dddbb7 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. @@ -51,18 +52,25 @@ // We mean it. // +#include <QtCore/private/qglobal_p.h> #include "qplatformdefs.h" #include "QtCore/qatomic.h" #include "QtCore/qdatetime.h" #include "QtCore/qpair.h" +#if QT_CONFIG(timezone) #include "qtimezone.h" +#endif 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 +84,6 @@ public: // Daylight Time Status enum DaylightStatus { - NoDaylightTime = -2, UnknownDaylightTime = -1, StandardTime = 0, DaylightTime = 1 @@ -84,67 +91,51 @@ 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) - {} - - QDateTimePrivate(const QDate &toDate, const QTime &toTime, Qt::TimeSpec toSpec, - int offsetSeconds); + ref(0) + { + } -#ifndef QT_BOOTSTRAPPED - QDateTimePrivate(const QDate &toDate, const QTime &toTime, const QTimeZone & timeZone); -#endif // QT_BOOTSTRAPPED + static QDateTime::Data create(const QDate &toDate, const QTime &toTime, Qt::TimeSpec toSpec, + int offsetSeconds); - // ### XXX: when the tooling situation improves, look at fixing the padding. - // 4 bytes padding +#if QT_CONFIG(timezone) + static QDateTime::Data create(const QDate &toDate, const QTime &toTime, const QTimeZone & timeZone); +#endif // timezone qint64 m_msecs; - Qt::TimeSpec m_spec; + StatusFlags m_status; int m_offsetFromUtc; -#ifndef QT_BOOTSTRAPPED + mutable QAtomicInt ref; +#if QT_CONFIG(timezone) 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); } +#endif // timezone -#ifndef QT_BOOTSTRAPPED +#if QT_CONFIG(timezone) static qint64 zoneMSecsToEpochMSecs(qint64 msecs, const QTimeZone &zone, QDate *localDate = 0, QTime *localTime = 0); -#endif // QT_BOOTSTRAPPED +#endif // timezone static inline qint64 minJd() { return QDate::minJd(); } static inline qint64 maxJd() { return QDate::maxJd(); } |