From 037369cc4d85c49e351c3df6544a398b61195656 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 11 Apr 2019 12:02:17 +0200 Subject: 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 Reviewed-by: Qt CI Bot --- tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/auto/corelib/time') 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")); } -- cgit v1.2.3 From b4b3b5c69469f67103309cb2f401c243d840cf4e Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 30 Jan 2020 17:24:01 +0100 Subject: Clarify handling of unspecified year in two QCalendar methods [ChangeLog][QtCore] QCalendar::monthsInYear(QCalendar::Unspecified) now returns maximumMonthsInYear(). QCalendar::daysInYear() now makes clear that its handling of unspecified year is undefined. Change-Id: Ifef8723193868c666f6afeb7f190af4929d30dea Reviewed-by: Paul Wicking Reviewed-by: Thiago Macieira --- .../auto/corelib/time/qcalendar/tst_qcalendar.cpp | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'tests/auto/corelib/time') diff --git a/tests/auto/corelib/time/qcalendar/tst_qcalendar.cpp b/tests/auto/corelib/time/qcalendar/tst_qcalendar.cpp index 9b41014394..5da69e76a5 100644 --- a/tests/auto/corelib/time/qcalendar/tst_qcalendar.cpp +++ b/tests/auto/corelib/time/qcalendar/tst_qcalendar.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2018 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -40,6 +40,8 @@ private: private slots: void basic_data(); void basic(); + void unspecified_data() { basic_data(); } + void unspecified(); void nameCase(); void specific_data(); void specific(); @@ -145,6 +147,27 @@ void tst_QCalendar::basic() NORMALYEAR(cal, year); } +void tst_QCalendar::unspecified() +{ + QFETCH(QCalendar::System, system); + QCalendar cal(system); + + const QDate today = QDate::currentDate(); + const int thisYear = today.year(); + QCOMPARE(cal.monthsInYear(QCalendar::Unspecified), cal.maximumMonthsInYear()); + for (int month = cal.maximumMonthsInYear(); month > 0; month--) { + const int days = cal.daysInMonth(month); + int count = 0; + // 19 years = one Metonic cycle (used by some lunar calendars) + for (int i = 19; i > 0; --i) { + if (cal.daysInMonth(month, thisYear - i) == days) + count++; + } + // Require a majority of the years tested: + QVERIFY2(count > 9, "Default daysInMonth() should be for a normal year"); + } +} + void tst_QCalendar::nameCase() { QVERIFY(QCalendar::availableCalendars().contains(QStringLiteral("Gregorian"))); -- cgit v1.2.3 From d6d98f782aeb798649c2bf5f7744065b7e86c035 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 22 Jan 2020 16:12:24 +0100 Subject: Deprecate locale-related DateFormat enum members Qt 6 shall remove all locale-dependence from Q(Date|Time)+. Task-number: QTBUG-80441 Change-Id: Iebaaa2bd776bccfe0d73c15f36cbdd456b71ca59 Reviewed-by: Fabian Kosmale --- tests/auto/corelib/time/qdate/tst_qdate.cpp | 4 +++- tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp | 17 ++++++++++++++--- tests/auto/corelib/time/qtime/tst_qtime.cpp | 6 +++++- 3 files changed, 22 insertions(+), 5 deletions(-) (limited to 'tests/auto/corelib/time') diff --git a/tests/auto/corelib/time/qdate/tst_qdate.cpp b/tests/auto/corelib/time/qdate/tst_qdate.cpp index 567209dcf6..274bf4f6f0 100644 --- a/tests/auto/corelib/time/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/time/qdate/tst_qdate.cpp @@ -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/ ** @@ -1352,6 +1352,7 @@ void tst_QDate::toStringDateFormat() QFETCH(Qt::DateFormat, format); QFETCH(QString, expectedStr); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QCOMPARE(date.toString(Qt::SystemLocaleShortDate), QLocale::system().toString(date, QLocale::ShortFormat)); QCOMPARE(date.toString(Qt::DefaultLocaleShortDate), QLocale().toString(date, QLocale::ShortFormat)); QCOMPARE(date.toString(Qt::SystemLocaleLongDate), QLocale::system().toString(date, QLocale::LongFormat)); @@ -1361,6 +1362,7 @@ void tst_QDate::toStringDateFormat() QCOMPARE(date.toString(Qt::DefaultLocaleShortDate), QLocale().toString(date, QLocale::ShortFormat)); QCOMPARE(date.toString(Qt::SystemLocaleLongDate), QLocale::system().toString(date, QLocale::LongFormat)); QCOMPARE(date.toString(Qt::DefaultLocaleLongDate), QLocale().toString(date, QLocale::LongFormat)); +#endif // ### Qt 6: remove QCOMPARE(date.toString(format), expectedStr); } diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index ec5f65ee56..26ad91271d 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -127,8 +127,10 @@ private slots: #ifdef Q_OS_WIN void fromString_LOCALE_ILDATE(); #endif +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void fromStringToStringLocale_data(); void fromStringToStringLocale(); +#endif // ### Qt 6: remove void offsetFromUtc(); void setOffsetFromUtc(); @@ -295,9 +297,9 @@ void tst_QDateTime::initTestCase() void tst_QDateTime::init() { -#if defined(Q_OS_WIN32) +#if defined(Q_OS_WIN32) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0) SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT)); -#endif +#endif // ### Qt 6: remove } QString tst_QDateTime::str( int y, int month, int d, int h, int min, int s ) @@ -834,8 +836,10 @@ void tst_QDateTime::toString_isoDate() QFETCH(Qt::DateFormat, format); QFETCH(QString, expected); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QLocale oldLocale; QLocale::setDefault(QLocale("en_US")); +#endif // ### Qt 6: remove QString result = datetime.toString(format); QCOMPARE(result, expected); @@ -854,7 +858,9 @@ void tst_QDateTime::toString_isoDate() QCOMPARE(resultDatetime, QDateTime()); } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QLocale::setDefault(oldLocale); +#endif // ### Qt 6: remove } void tst_QDateTime::toString_isoDate_extra() @@ -1763,7 +1769,7 @@ void tst_QDateTime::daylightSavingsTimeChange() // because some functions did not reset the flag when moving in or out of DST. // WARNING: This only tests anything if there's a Daylight Savings Time change - // in the current locale between inDST and outDST. + // in the current time-zone between inDST and outDST. // This is true for Central European Time and may be elsewhere. QFETCH(QDate, inDST); @@ -2612,6 +2618,9 @@ void tst_QDateTime::fromString_LOCALE_ILDATE() } #endif +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED + void tst_QDateTime::fromStringToStringLocale_data() { QTest::addColumn("locale"); @@ -2643,6 +2652,8 @@ void tst_QDateTime::fromStringToStringLocale() #undef ROUNDTRIP QLocale::setDefault(def); } +QT_WARNING_POP +#endif // ### Qt 6: remove void tst_QDateTime::offsetFromUtc() { diff --git a/tests/auto/corelib/time/qtime/tst_qtime.cpp b/tests/auto/corelib/time/qtime/tst_qtime.cpp index f85e0ea74e..027232f6d5 100644 --- a/tests/auto/corelib/time/qtime/tst_qtime.cpp +++ b/tests/auto/corelib/time/qtime/tst_qtime.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -77,7 +77,9 @@ private slots: void toStringDateFormat(); void toStringFormat_data(); void toStringFormat(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void toStringLocale(); +#endif // ### Qt 6: remove void msecsSinceStartOfDay_data(); void msecsSinceStartOfDay(); @@ -770,6 +772,7 @@ void tst_QTime::toStringFormat() QCOMPARE( t.toString( format ), str ); } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void tst_QTime::toStringLocale() { QTime time(18, 30); @@ -791,6 +794,7 @@ void tst_QTime::toStringLocale() QCOMPARE(time.toString(Qt::DefaultLocaleLongDate), QLocale().toString(time, QLocale::LongFormat)); } +#endif // ### Qt 6: remove void tst_QTime::msecsSinceStartOfDay_data() { -- cgit v1.2.3