summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qdatetime.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qdatetime.h')
-rw-r--r--src/corelib/tools/qdatetime.h91
1 files changed, 57 insertions, 34 deletions
diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h
index a75d7d9bc8..88288872df 100644
--- a/src/corelib/tools/qdatetime.h
+++ b/src/corelib/tools/qdatetime.h
@@ -1,7 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
@@ -10,9 +10,9 @@
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -23,8 +23,8 @@
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
@@ -40,6 +40,13 @@
#include <limits>
+#ifdef Q_OS_MAC
+Q_FORWARD_DECLARE_CF_TYPE(CFDate);
+# ifdef __OBJC__
+Q_FORWARD_DECLARE_OBJC_CLASS(NSDate);
+# endif
+#endif
+
QT_BEGIN_NAMESPACE
class QTimeZone;
@@ -51,12 +58,14 @@ public:
DateFormat = 0,
StandaloneFormat
};
+private:
+ Q_DECL_CONSTEXPR QDate(qint64 julianDay) : jd(julianDay) {}
public:
- QDate() { jd = nullJd(); }
+ Q_DECL_CONSTEXPR QDate() : jd(nullJd()) {}
QDate(int y, int m, int d);
- bool isNull() const { return !isValid(); }
- bool isValid() const { return jd >= minJd() && jd <= maxJd(); }
+ Q_DECL_CONSTEXPR bool isNull() const { return !isValid(); }
+ Q_DECL_CONSTEXPR bool isValid() const { return jd >= minJd() && jd <= maxJd(); }
int year() const;
int month() const;
@@ -91,12 +100,12 @@ QT_DEPRECATED inline bool setYMD(int y, int m, int d)
QDate addYears(int years) const Q_REQUIRED_RESULT;
qint64 daysTo(const QDate &) const;
- bool operator==(const QDate &other) const { return jd == other.jd; }
- bool operator!=(const QDate &other) const { return jd != other.jd; }
- bool operator<(const QDate &other) const { return jd < other.jd; }
- bool operator<=(const QDate &other) const { return jd <= other.jd; }
- bool operator>(const QDate &other) const { return jd > other.jd; }
- bool operator>=(const QDate &other) const { return jd >= other.jd; }
+ Q_DECL_CONSTEXPR bool operator==(const QDate &other) const { return jd == other.jd; }
+ Q_DECL_CONSTEXPR bool operator!=(const QDate &other) const { return jd != other.jd; }
+ Q_DECL_CONSTEXPR bool operator< (const QDate &other) const { return jd < other.jd; }
+ Q_DECL_CONSTEXPR bool operator<=(const QDate &other) const { return jd <= other.jd; }
+ Q_DECL_CONSTEXPR bool operator> (const QDate &other) const { return jd > other.jd; }
+ Q_DECL_CONSTEXPR bool operator>=(const QDate &other) const { return jd >= other.jd; }
static QDate currentDate();
#ifndef QT_NO_DATESTRING
@@ -106,15 +115,15 @@ QT_DEPRECATED inline bool setYMD(int y, int m, int d)
static bool isValid(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; }
- inline qint64 toJulianDay() const { return jd; }
+ static Q_DECL_CONSTEXPR inline QDate fromJulianDay(qint64 jd)
+ { return jd >= minJd() && jd <= maxJd() ? QDate(jd) : QDate() ; }
+ Q_DECL_CONSTEXPR inline qint64 toJulianDay() const { return jd; }
private:
// using extra parentheses around min to avoid expanding it if it is a macro
- static inline qint64 nullJd() { return (std::numeric_limits<qint64>::min)(); }
- static inline qint64 minJd() { return Q_INT64_C(-784350574879); }
- static inline qint64 maxJd() { return Q_INT64_C( 784354017364); }
+ static Q_DECL_CONSTEXPR inline qint64 nullJd() { return (std::numeric_limits<qint64>::min)(); }
+ static Q_DECL_CONSTEXPR inline qint64 minJd() { return Q_INT64_C(-784350574879); }
+ static Q_DECL_CONSTEXPR inline qint64 maxJd() { return Q_INT64_C( 784354017364); }
qint64 jd;
@@ -129,15 +138,20 @@ Q_DECLARE_TYPEINFO(QDate, Q_MOVABLE_TYPE);
class Q_CORE_EXPORT QTime
{
+ Q_DECL_CONSTEXPR QTime(int ms) : mds(ms)
+#if defined(Q_OS_WINCE)
+ , startTick(NullTime)
+#endif
+ {}
public:
- QTime(): mds(NullTime)
+ Q_DECL_CONSTEXPR QTime(): mds(NullTime)
#if defined(Q_OS_WINCE)
, startTick(NullTime)
#endif
{}
QTime(int h, int m, int s = 0, int ms = 0);
- bool isNull() const { return mds == NullTime; }
+ Q_DECL_CONSTEXPR bool isNull() const { return mds == NullTime; }
bool isValid() const;
int hour() const;
@@ -155,15 +169,15 @@ public:
QTime addMSecs(int ms) const Q_REQUIRED_RESULT;
int msecsTo(const QTime &) const;
- 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; }
- bool operator>(const QTime &other) const { return mds > other.mds; }
- bool operator>=(const QTime &other) const { return mds >= other.mds; }
+ Q_DECL_CONSTEXPR bool operator==(const QTime &other) const { return mds == other.mds; }
+ Q_DECL_CONSTEXPR bool operator!=(const QTime &other) const { return mds != other.mds; }
+ Q_DECL_CONSTEXPR bool operator< (const QTime &other) const { return mds < other.mds; }
+ Q_DECL_CONSTEXPR bool operator<=(const QTime &other) const { return mds <= other.mds; }
+ Q_DECL_CONSTEXPR bool operator> (const QTime &other) const { return mds > other.mds; }
+ Q_DECL_CONSTEXPR bool operator>=(const QTime &other) const { return mds >= other.mds; }
- static inline QTime fromMSecsSinceStartOfDay(int msecs) { QTime t; t.mds = msecs; return t; }
- inline int msecsSinceStartOfDay() const { return mds == NullTime ? 0 : mds; }
+ static Q_DECL_CONSTEXPR inline QTime fromMSecsSinceStartOfDay(int msecs) { return QTime(msecs); }
+ Q_DECL_CONSTEXPR inline int msecsSinceStartOfDay() const { return mds == NullTime ? 0 : mds; }
static QTime currentTime();
#ifndef QT_NO_DATESTRING
@@ -177,7 +191,7 @@ public:
int elapsed() const;
private:
enum TimeFlag { NullTime = -1 };
- inline int ds() const { return mds == -1 ? 0 : mds; }
+ Q_DECL_CONSTEXPR inline int ds() const { return mds == -1 ? 0 : mds; }
int mds;
#if defined(Q_OS_WINCE)
int startTick;
@@ -296,6 +310,15 @@ public:
#endif
static qint64 currentMSecsSinceEpoch() Q_DECL_NOTHROW;
+#if defined(Q_OS_MAC) || defined(Q_QDOC)
+ static QDateTime fromCFDate(CFDateRef date);
+ CFDateRef toCFDate() const Q_DECL_CF_RETURNS_RETAINED;
+# if defined(__OBJC__) || defined(Q_QDOC)
+ static QDateTime fromNSDate(const NSDate *date);
+ NSDate *toNSDate() const Q_DECL_NS_RETURNS_AUTORELEASED;
+# endif
+#endif
+
private:
friend class QDateTimePrivate;
void detach();
@@ -303,7 +326,7 @@ private:
// ### Qt6: Using a private here has high impact on runtime
// on users such as QFileInfo. In Qt 6, the data members
// should be inlined.
- QExplicitlySharedDataPointer<QDateTimePrivate> d;
+ QSharedDataPointer<QDateTimePrivate> d;
#ifndef QT_NO_DATASTREAM
friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QDateTime &);