diff --git a/autotests/testicalformat.h b/autotests/testicalformat.h --- a/autotests/testicalformat.h +++ b/autotests/testicalformat.h @@ -33,6 +33,7 @@ void testVolatileProperties(); void testCuType(); void testAlarm(); + void testReadFromString(); }; #endif diff --git a/autotests/testicalformat.cpp b/autotests/testicalformat.cpp --- a/autotests/testicalformat.cpp +++ b/autotests/testicalformat.cpp @@ -170,3 +170,42 @@ Alarm::Ptr alarm2 = event2->alarms()[0]; QCOMPARE(*alarm, *alarm2); } + +void ICalFormatTest::testReadFromString() +{ + ICalFormat format; + + const QString icsDataWithout + = QLatin1String("BEGIN:VCALENDAR\n" \ + "PRODID:-//K Desktop Environment//NONSGML libkcal 3.2//EN\n" \ + "VERSION:2.0\n" \ + "BEGIN:VEVENT\n" \ + "UID:123-456-789\n" \ + "SUMMARY:Test no created or last modified\n" \ + "DTSTART;TZID=Europe/Paris:20200114\n" \ + "END:VEVENT\n" \ + "END:VCALENDAR"); + Incidence::Ptr event = format.fromString(icsDataWithout); + + QVERIFY(event); + QVERIFY(!event->created().isValid()); + QVERIFY(!event->lastModified().isValid()); + + const QString icsDataWith + = QLatin1String("BEGIN:VCALENDAR\n" \ + "PRODID:-//K Desktop Environment//NONSGML libkcal 3.2//EN\n" \ + "VERSION:2.0\n" \ + "BEGIN:VEVENT\n" \ + "UID:123-456-789\n" \ + "CREATED: 20200114T141312Z\n" \ + "LAST-MODIFIED: 20200114T151312Z\n" \ + "SUMMARY:Test no created or last modified\n" \ + "DTSTART;TZID=Europe/Paris:20200114\n" \ + "END:VEVENT\n" \ + "END:VCALENDAR"); + Incidence::Ptr event2 = format.fromString(icsDataWith); + + QVERIFY(event2); + QVERIFY(event2->created().isValid()); + QVERIFY(event2->lastModified().isValid()); +} diff --git a/src/icalformat_p.cpp b/src/icalformat_p.cpp --- a/src/icalformat_p.cpp +++ b/src/icalformat_p.cpp @@ -1173,6 +1173,8 @@ Todo::Ptr ICalFormatImpl::readTodo(icalcomponent *vtodo, const ICalTimeZoneCache *tzlist) { Todo::Ptr todo(new Todo); + todo->setCreated(QDateTime()); + todo->setLastModified(QDateTime()); readIncidence(vtodo, todo, tzlist); @@ -1239,6 +1241,8 @@ Event::Ptr ICalFormatImpl::readEvent(icalcomponent *vevent, const ICalTimeZoneCache *tzlist) { Event::Ptr event(new Event); + event->setCreated(QDateTime()); + event->setLastModified(QDateTime()); readIncidence(vevent, event, tzlist); @@ -1404,6 +1408,9 @@ Journal::Ptr ICalFormatImpl::readJournal(icalcomponent *vjournal, const ICalTimeZoneCache *tzList) { Journal::Ptr journal(new Journal); + journal->setCreated(QDateTime()); + journal->setLastModified(QDateTime()); + readIncidence(vjournal, journal, tzList); journal->resetDirtyFields();