From c94d41d903e8978efc084ff96e1ac45a46feb6e8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 14 Oct 2014 18:15:38 +0200 Subject: [PATCH] QDateTime: prepare for constexpr'ification Make sure from{JulianDay,MSecsSinceStartOfDay}() are in a constexpr'able form by introducing new private ctors that allow formulating these functions as single expressions. Change-Id: Iee98edb74e63c32e98781b885bbb2c5ef5867fd9 Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetime.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h index d305069d45..3affc7e9aa 100644 --- a/src/corelib/tools/qdatetime.h +++ b/src/corelib/tools/qdatetime.h @@ -58,6 +58,8 @@ public: DateFormat = 0, StandaloneFormat }; +private: + QDate(qint64 julianDay) : jd(julianDay) {} public: QDate() { jd = nullJd(); } QDate(int y, int m, int d); @@ -114,7 +116,7 @@ QT_DEPRECATED inline bool setYMD(int y, int m, int d) static bool isLeapYear(int year); static inline QDate fromJulianDay(qint64 jd) - { QDate d; if (jd >= minJd() && jd <= maxJd()) d.jd = jd; return d; } + { return jd >= minJd() && jd <= maxJd() ? QDate(jd) : QDate() ; } inline qint64 toJulianDay() const { return jd; } private: @@ -136,6 +138,11 @@ Q_DECLARE_TYPEINFO(QDate, Q_MOVABLE_TYPE); class Q_CORE_EXPORT QTime { + QTime(int ms) : mds(ms) +#if defined(Q_OS_WINCE) + , startTick(NullTime) +#endif + {} public: QTime(): mds(NullTime) #if defined(Q_OS_WINCE) @@ -169,7 +176,7 @@ public: bool operator>(const QTime &other) const { return mds > other.mds; } bool operator>=(const QTime &other) const { return mds >= other.mds; } - static inline QTime fromMSecsSinceStartOfDay(int msecs) { QTime t; t.mds = msecs; return t; } + static inline QTime fromMSecsSinceStartOfDay(int msecs) { return QTime(msecs); } inline int msecsSinceStartOfDay() const { return mds == NullTime ? 0 : mds; } static QTime currentTime();