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 <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2014-10-14 18:15:38 +02:00
parent f2e3fdc803
commit c94d41d903

View File

@ -58,6 +58,8 @@ public:
DateFormat = 0, DateFormat = 0,
StandaloneFormat StandaloneFormat
}; };
private:
QDate(qint64 julianDay) : jd(julianDay) {}
public: public:
QDate() { jd = nullJd(); } QDate() { jd = nullJd(); }
QDate(int y, int m, int d); 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 bool isLeapYear(int year);
static inline QDate fromJulianDay(qint64 jd) 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; } inline qint64 toJulianDay() const { return jd; }
private: private:
@ -136,6 +138,11 @@ Q_DECLARE_TYPEINFO(QDate, Q_MOVABLE_TYPE);
class Q_CORE_EXPORT QTime class Q_CORE_EXPORT QTime
{ {
QTime(int ms) : mds(ms)
#if defined(Q_OS_WINCE)
, startTick(NullTime)
#endif
{}
public: public:
QTime(): mds(NullTime) QTime(): mds(NullTime)
#if defined(Q_OS_WINCE) #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; }
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; } inline int msecsSinceStartOfDay() const { return mds == NullTime ? 0 : mds; }
static QTime currentTime(); static QTime currentTime();