From 740ff4780303b9934d1c1c26ea13fd3cb85872d4 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 5 Dec 2024 15:28:07 +0800 Subject: [PATCH] Use QTimeZone in startOfDay for QDate in tests Signed-off-by: Claudio Cambra --- test/testdatefieldbackend.cpp | 8 ++++---- test/testsharemodel.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/testdatefieldbackend.cpp b/test/testdatefieldbackend.cpp index 2ce760813b743..96f2ba1dafa64 100644 --- a/test/testdatefieldbackend.cpp +++ b/test/testdatefieldbackend.cpp @@ -44,7 +44,7 @@ private slots: backend._dateFormat = dateStringFormat; const auto currentDate = QDate::currentDate(); - const auto currentDateMSecs = currentDate.startOfDay(Qt::UTC).toMSecsSinceEpoch(); + const auto currentDateMSecs = currentDate.startOfDay(QTimeZone::utc()).toMSecsSinceEpoch(); const auto currentDateString = currentDate.toString(dateStringFormat); QCOMPARE(backend.date(), currentDate); @@ -64,8 +64,8 @@ private slots: const auto minDate = QDate::currentDate().addDays(-5); const auto maxDate = QDate::currentDate().addDays(5); - const auto minDateMs = minDate.startOfDay(Qt::UTC).toMSecsSinceEpoch(); - const auto maxDateMs = maxDate.startOfDay(Qt::UTC).toMSecsSinceEpoch(); + const auto minDateMs = minDate.startOfDay(QTimeZone::utc()).toMSecsSinceEpoch(); + const auto maxDateMs = maxDate.startOfDay(QTimeZone::utc()).toMSecsSinceEpoch(); const auto invalidMinDate = minDate.addDays(-1); const auto invalidMaxDate = maxDate.addDays(1); @@ -124,7 +124,7 @@ private slots: QSignalSpy dateStringChangedSpy(&backend, &Quick::DateFieldBackend::dateStringChanged); const auto testDate = QDate::currentDate().addDays(800); - const auto testDateMsecs = testDate.startOfDay(Qt::UTC).toMSecsSinceEpoch(); + const auto testDateMsecs = testDate.startOfDay(QTimeZone::utc()).toMSecsSinceEpoch(); const auto testDateString = testDate.toString(dateStringFormat); backend.setDate(testDate); diff --git a/test/testsharemodel.cpp b/test/testsharemodel.cpp index 5d8800985b905..6abfe79ce731a 100644 --- a/test/testsharemodel.cpp +++ b/test/testsharemodel.cpp @@ -278,7 +278,7 @@ private slots: const auto expectedLinkShareExpireDate = QDate::fromString(_testLinkShareDefinition.shareExpiration, helper.expectedDtFormat); QCOMPARE(shareIndex.data(ShareModel::ExpireDateEnabledRole).toBool(), expectedLinkShareExpireDate.isValid()); - QCOMPARE(shareIndex.data(ShareModel::ExpireDateRole).toLongLong(), expectedLinkShareExpireDate.startOfDay(Qt::UTC).toMSecsSinceEpoch()); + QCOMPARE(shareIndex.data(ShareModel::ExpireDateRole).toLongLong(), expectedLinkShareExpireDate.startOfDay(QTimeZone::utc()).toMSecsSinceEpoch()); const auto iconUrl = shareIndex.data(ShareModel::IconUrlRole).toString(); QVERIFY(iconUrl.contains("public.svg")); @@ -321,7 +321,7 @@ private slots: const auto expectedShareExpireDate = QDate::fromString(_testEmailShareDefinition.shareExpiration, helper.expectedDtFormat); QCOMPARE(shareIndex.data(ShareModel::ExpireDateEnabledRole).toBool(), expectedShareExpireDate.isValid()); - QCOMPARE(shareIndex.data(ShareModel::ExpireDateRole).toLongLong(), expectedShareExpireDate.startOfDay(Qt::UTC).toMSecsSinceEpoch()); + QCOMPARE(shareIndex.data(ShareModel::ExpireDateRole).toLongLong(), expectedShareExpireDate.startOfDay(QTimeZone::utc()).toMSecsSinceEpoch()); const auto iconUrl = shareIndex.data(ShareModel::IconUrlRole).toString(); QVERIFY(iconUrl.contains("email.svg")); @@ -364,7 +364,7 @@ private slots: const auto expectedShareExpireDate = QDate::fromString(_testUserShareDefinition.shareExpiration, helper.expectedDtFormat); QCOMPARE(shareIndex.data(ShareModel::ExpireDateEnabledRole).toBool(), expectedShareExpireDate.isValid()); - QCOMPARE(shareIndex.data(ShareModel::ExpireDateRole).toLongLong(), expectedShareExpireDate.startOfDay(Qt::UTC).toMSecsSinceEpoch()); + QCOMPARE(shareIndex.data(ShareModel::ExpireDateRole).toLongLong(), expectedShareExpireDate.startOfDay(QTimeZone::utc()).toMSecsSinceEpoch()); const auto iconUrl = shareIndex.data(ShareModel::IconUrlRole).toString(); QVERIFY(iconUrl.contains("user.svg")); @@ -801,14 +801,14 @@ private slots: QCOMPARE(shareIndex.data(ShareModel::ExpireDateEnabledRole).toBool(), false); // Set a new expire date - const auto expireDateMsecs = QDate::currentDate().addDays(10).startOfDay(Qt::UTC).toMSecsSinceEpoch(); + const auto expireDateMsecs = QDate::currentDate().addDays(10).startOfDay(QTimeZone::utc()).toMSecsSinceEpoch(); model.setShareExpireDate(linkSharePtr, expireDateMsecs); QVERIFY(expireDateSet.wait(3000)); QCOMPARE(shareIndex.data(ShareModel::ExpireDateRole).toLongLong(), expireDateMsecs); QCOMPARE(shareIndex.data(ShareModel::ExpireDateEnabledRole).toBool(), true); // Test the QML-specific slot - const QVariant newExpireDateMsecs = QDate::currentDate().addDays(20).startOfDay(Qt::UTC).toMSecsSinceEpoch(); + const QVariant newExpireDateMsecs = QDate::currentDate().addDays(20).startOfDay(QTimeZone::utc()).toMSecsSinceEpoch(); model.setShareExpireDateFromQml(QVariant::fromValue(sharePtr), newExpireDateMsecs); QVERIFY(expireDateSet.wait(3000)); QCOMPARE(shareIndex.data(ShareModel::ExpireDateRole).toLongLong(), newExpireDateMsecs);