summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2014-10-14 18:15:38 +0200
committerMarc Mutz <marc.mutz@kdab.com>2015-02-12 19:40:14 +0000
commitc94d41d903e8978efc084ff96e1ac45a46feb6e8 (patch)
treed1f9994f3358f8348060344607920f1d8dc67a53
parentf2e3fdc803b9842b6ba4aefe7becdd42eafc4d38 (diff)
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>
-rw-r--r--src/corelib/tools/qdatetime.h11
1 files 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();