summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qdatetime_p.h
diff options
context:
space:
mode:
authorJohn Layt <jlayt@kde.org>2013-08-12 21:21:42 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-20 23:45:06 +0200
commit18322bfabc3c349040bb370167e2642dc734bd50 (patch)
tree8846f14fb26728b8e93849c96ba10d4d1602c980 /src/corelib/tools/qdatetime_p.h
parent662f23ff5b418cd213a3f3328cf28b53b2617de5 (diff)
QDateTime - Change date/time storage to msecs
Change from storing the date and time as QDate and QTime to a serialised msecs format. This format is a direct translation of the QDate and QTime values, it is not the actual msecs since the Unix epoch. This msecs format ensures we are always able to recreate the original QDate and QTime values, but should still simplify the code and improve performance. Because we no longer store the explicit date and time we need to store their isNull()/isValid() status separately. The changes in storage results in the same memory footprint as before. Note that this change does not optimize the code nor set out to fix the known bugs, it only seeks to maintain the current behavior, although some bugs are fixed implicitly. More bug fixes and optimizations will follow. [ChangeLog][Important Behavior Changes] The supported date range in QDateTime has been reduced to about +/- 292 million years, the range supported by the number of msecs since the Unix epoch of 1 Jan 1970 as stored in a qint64, and as able to be used in the setMSecsSinceEpoch() and toMSecsSinceEpoch() methods. Change-Id: I98804d8781909555d3313a3a7080eb8e70cb46ad Reviewed-by: Sérgio Martins <sergio.martins@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qdatetime_p.h')
-rw-r--r--src/corelib/tools/qdatetime_p.h45
1 files changed, 31 insertions, 14 deletions
diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h
index e6cece141d..124bd98a31 100644
--- a/src/corelib/tools/qdatetime_p.h
+++ b/src/corelib/tools/qdatetime_p.h
@@ -80,28 +80,45 @@ public:
DaylightTime
};
- QDateTimePrivate() : m_spec(Qt::LocalTime), m_offsetFromUtc(0) {}
+ // Status of date/time
+ enum StatusFlag {
+ NullDate = 0x01,
+ NullTime = 0x02,
+ ValidDate = 0x04,
+ ValidTime = 0x08,
+ };
+ Q_DECLARE_FLAGS(StatusFlags, StatusFlag)
+
+ QDateTimePrivate() : m_msecs(0),
+ m_spec(Qt::LocalTime),
+ m_offsetFromUtc(0),
+ m_status(NullDate | NullTime)
+ {}
+
QDateTimePrivate(const QDate &toDate, const QTime &toTime, Qt::TimeSpec toSpec,
int offsetSeconds);
- QDateTimePrivate(const QDateTimePrivate &other)
- : QSharedData(other), date(other.date), time(other.time), m_spec(other.m_spec),
- m_offsetFromUtc(other.m_offsetFromUtc)
+
+ QDateTimePrivate(const QDateTimePrivate &other) : QSharedData(other),
+ m_msecs(other.m_msecs),
+ m_spec(other.m_spec),
+ m_offsetFromUtc(other.m_offsetFromUtc),
+ m_status(other.m_status)
{}
- QDate date;
- QTime time;
+ qint64 m_msecs;
Qt::TimeSpec m_spec;
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 put result in utcDate and utcTime
- static void addMSecs(QDate &utcDate, QTime &utcTime, qint64 msecs);
+ StatusFlags m_status;
void setTimeSpec(Qt::TimeSpec spec, int offsetSeconds);
+ void setDateTime(const QDate &date, const QTime &time);
+ void getDateTime(QDate *date, QTime *time) const;
+
+ // Get/set date and time status
+ inline bool isNullDate() const { return (m_status & NullDate) == NullDate; }
+ inline bool isNullTime() const { return (m_status & NullTime) == NullTime; }
+ inline bool isValidDate() const { return (m_status & ValidDate) == ValidDate; }
+ inline bool isValidTime() const { return (m_status & ValidTime) == ValidTime; }
static inline qint64 minJd() { return QDate::minJd(); }
static inline qint64 maxJd() { return QDate::maxJd(); }