diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2019-04-11 12:02:17 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2020-01-30 19:56:21 +0100 |
commit | 037369cc4d85c49e351c3df6544a398b61195656 (patch) | |
tree | 72679f5a745c6b057290f313545d7b279f62a96d | |
parent | 6a1df2d2060bfa346398f6125f33a4ff1b190a64 (diff) |
Deprecate QDateTime(const QDate &) in favor of QDate::startOfDay()
It needed re-implemented in terms of the new API (in case QTime(0, 0)
was skipped, on the date in question, by a spring-forwrd), which makes
it redundant (and supports choice of spec and zone or offset, which it
did not).
Change-Id: I1e3c3e794632c234f254be754ed6e4ebdaaaa6bc
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 6 | ||||
-rw-r--r-- | src/corelib/time/qdatetime.cpp | 11 | ||||
-rw-r--r-- | src/corelib/time/qdatetime.h | 6 | ||||
-rw-r--r-- | tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp | 6 |
4 files changed, 17 insertions, 12 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index b417683d2a..3be9a02248 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2019 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Copyright (C) 2018 Intel Corporation. ** Copyright (C) 2015 Olivier Goffart <ogoffart@woboq.com> ** Contact: https://www.qt.io/licensing/ @@ -662,7 +662,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) # endif #endif case QMetaType::QDate: - *dt = QDateTime(*v_cast<QDate>(d)); + *dt = v_cast<QDate>(d)->startOfDay(); break; default: return false; @@ -1229,7 +1229,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) *static_cast<QCborValue *>(result) = *v_cast<QByteArray>(d); break; case QMetaType::QDate: - *static_cast<QCborValue *>(result) = QCborValue(QDateTime(*v_cast<QDate>(d))); + *static_cast<QCborValue *>(result) = QCborValue(v_cast<QDate>(d)->startOfDay()); break; case QMetaType::QDateTime: *static_cast<QCborValue *>(result) = QCborValue(*v_cast<QDateTime>(d)); diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 80751e60a0..7cc8568bd5 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -3631,15 +3631,18 @@ QDateTime::QDateTime() noexcept(Data::CanBeSmall) } +#if QT_DEPRECATED_SINCE(5, 17) // ### Qt 6: remove /*! - Constructs a datetime with the given \a date, a valid - time(00:00:00.000), and sets the timeSpec() to Qt::LocalTime. -*/ + Constructs a datetime with the given \a date, using Qt::LocalTime as the + timeSpec() and the time at the start of that date. + \sa QDate::startOfDay() +*/ QDateTime::QDateTime(const QDate &date) - : d(QDateTimePrivate::create(date, QTime(0, 0), Qt::LocalTime, 0)) + : QDateTime(date.startOfDay(Qt::LocalTime, 0)) { } +#endif /*! Constructs a datetime with the given \a date and \a time, using diff --git a/src/corelib/time/qdatetime.h b/src/corelib/time/qdatetime.h index 3eae8ebf64..2c2b52b1c2 100644 --- a/src/corelib/time/qdatetime.h +++ b/src/corelib/time/qdatetime.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2019 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Copyright (C) 2016 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** @@ -287,7 +287,9 @@ class Q_CORE_EXPORT QDateTime public: QDateTime() noexcept(Data::CanBeSmall); - explicit QDateTime(const QDate &); // ### Qt 6: plain QDate, QTime +#if QT_DEPRECATED_SINCE(5, 15) // ### Qt 6: remove + QT_DEPRECATED_X("Use QDate::startOfDay()") explicit QDateTime(const QDate &); +#endif QDateTime(const QDate &, const QTime &, Qt::TimeSpec spec = Qt::LocalTime); // ### Qt 6: Merge with above with default offsetSeconds = 0 QDateTime(const QDate &date, const QTime &time, Qt::TimeSpec spec, int offsetSeconds); diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 6aae91f62f..ec5f65ee56 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -2941,19 +2941,19 @@ void tst_QDateTime::fewDigitsInYear() const void tst_QDateTime::printNegativeYear() const { { - QDateTime date(QDate(-20, 10, 11)); + QDateTime date(QDate(-20, 10, 11).startOfDay()); QVERIFY(date.isValid()); QCOMPARE(date.toString(QLatin1String("yyyy")), QString::fromLatin1("-0020")); } { - QDateTime date(QDate(-3, 10, 11)); + QDateTime date(QDate(-3, 10, 11).startOfDay()); QVERIFY(date.isValid()); QCOMPARE(date.toString(QLatin1String("yyyy")), QString::fromLatin1("-0003")); } { - QDateTime date(QDate(-400, 10, 11)); + QDateTime date(QDate(-400, 10, 11).startOfDay()); QVERIFY(date.isValid()); QCOMPARE(date.toString(QLatin1String("yyyy")), QString::fromLatin1("-0400")); } |