diff --git a/autotests/testrecurtodo.cpp b/autotests/testrecurtodo.cpp index 103241d350615d6d09a3bf8281c89e2f51ff64cf..9270c0c214164c80874256663e1880b129daced9 100644 --- a/autotests/testrecurtodo.cpp +++ b/autotests/testrecurtodo.cpp @@ -15,13 +15,26 @@ QTEST_MAIN(RecurTodoTest) using namespace KCalendarCore; +void RecurTodoTest::setTimeZone(const char* zonename) +{ + QVERIFY(QTimeZone(zonename).isValid()); + qputenv("TZ", zonename); + const QDateTime currentDateTime = QDateTime::currentDateTime(); + QVERIFY(currentDateTime.timeZone().isValid()); + QCOMPARE(currentDateTime.timeZoneAbbreviation(), QString::fromLatin1(zonename)); +} + + void RecurTodoTest::testAllDay() { - qputenv("TZ", "GMT"); + setTimeZone("UTC"); const QDate currentDate = QDate::currentDate(); const QDateTime currentUtcDateTime = QDateTime::currentDateTimeUtc(); const QDate dueDate(QDate::currentDate()); + QCOMPARE(currentDate, dueDate); + QCOMPARE(currentDate, currentUtcDateTime.date()); + Todo *todo = new Todo(); todo->setDtStart(QDateTime(dueDate.addDays(-1), {})); todo->setDtDue(QDateTime(dueDate, {})); @@ -29,14 +42,17 @@ void RecurTodoTest::testAllDay() todo->setAllDay(true); QCOMPARE(todo->dtStart().daysTo(todo->dtDue()), 1); + QVERIFY(!todo->recurs()); Recurrence *recurrence = todo->recurrence(); recurrence->unsetRecurs(); recurrence->setDaily(1); QCOMPARE(todo->dtDue(), QDateTime(dueDate, {})); + QCOMPARE(todo->percentComplete(), 0); + QVERIFY(todo->recurs()); // Previously it did not recur todo->setCompleted(currentUtcDateTime); QVERIFY(todo->recurs()); - QVERIFY(todo->percentComplete() == 0); + QCOMPARE(todo->percentComplete(), 0); // It is still not done const QDate newStartDate = todo->dtStart().date(); const QDate newDueDate = todo->dtDue().date(); QCOMPARE(newStartDate, currentDate); @@ -50,7 +66,7 @@ void RecurTodoTest::testAllDay() void RecurTodoTest::testRecurrenceStart() { - qputenv("TZ", "GMT"); + setTimeZone("UTC"); const QDateTime currentDateTime = QDateTime::currentDateTime(); const QDate currentDate = currentDateTime.date(); const QTime currentTimeWithMS = currentDateTime.time(); @@ -73,7 +89,7 @@ void RecurTodoTest::testRecurrenceStart() void RecurTodoTest::testNonAllDay() { - qputenv("TZ", "GMT"); + setTimeZone("UTC"); const QDateTime currentDateTime = QDateTime::currentDateTime(); const QDate currentDate = currentDateTime.date(); const QTime currentTimeWithMS = currentDateTime.time(); diff --git a/autotests/testrecurtodo.h b/autotests/testrecurtodo.h index 9374f06a7c5981a54aca304a90de042a4a16be02..7e44670f8dafc45db455e2685bd8a7cfa6915161 100644 --- a/autotests/testrecurtodo.h +++ b/autotests/testrecurtodo.h @@ -14,6 +14,8 @@ class RecurTodoTest : public QObject { Q_OBJECT +private: + void setTimeZone(const char* zonename); private Q_SLOTS: void testAllDay(); void testNonAllDay(); diff --git a/autotests/testtodo.cpp b/autotests/testtodo.cpp index 99ae9cdaaf0a855b5405486c4dc18ec8bf71e5d7..1684a7c8a34f71820a3b43af1f41c41246807d07 100644 --- a/autotests/testtodo.cpp +++ b/autotests/testtodo.cpp @@ -17,7 +17,7 @@ using namespace KCalendarCore; void TodoTest::initTestCase() { - qputenv("TZ", "GMT"); + qputenv("TZ", "UTC"); } void TodoTest::testValidity()