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>
bb10
Edward Welbourne 2019-04-11 12:02:17 +02:00
parent 6a1df2d206
commit 037369cc4d
4 changed files with 17 additions and 12 deletions

View File

@ -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));

View File

@ -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

View File

@ -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);

View File

@ -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"));
}