Skip to content

Commit

Permalink
Use QTimeZone in startOfDay for QDate in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
  • Loading branch information
claucambra committed Dec 5, 2024
1 parent cedb807 commit 67202d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions test/testdatefieldbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions test/testsharemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 67202d5

Please sign in to comment.