Commit 33032d5d authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

PimEventsPlugin: fix timezone handling in unit-tests

parent 415cc2c3
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//K Desktop Environment//NONSGML KOrganizer 5.2.50 pre
BEGIN:VEVENT
DTSTAMP:20160529T143409Z
CREATED:20160529T143351Z
......
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//K Desktop Environment//NONSGML KOrganizer 5.2.50 pre
BEGIN:VEVENT
DTSTAMP:20160529T143104Z
CREATED:20160529T143019Z
......
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//K Desktop Environment//NONSGML KOrganizer 5.2.50 pre
BEGIN:VEVENT
DTSTAMP:20160529T143448Z
CREATED:20160529T143412Z
......
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//K Desktop Environment//NONSGML KOrganizer 5.2.50 pre
BEGIN:VEVENT
DTSTAMP:20160529T143257Z
CREATED:20160529T143223Z
......
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//K Desktop Environment//NONSGML KOrganizer 5.2.50 pre
BEGIN:VEVENT
DTSTAMP:20160529T143349Z
CREATED:20160529T143303Z
......
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//K Desktop Environment//NONSGML KOrganizer 5.2.50 pre
BEGIN:VEVENT
DTSTAMP:20160529T143018Z
CREATED:20160529T142843Z
......
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//K Desktop Environment//NONSGML KOrganizer 5.2.50 pre
BEGIN:VEVENT
DTSTAMP:20160529T143526Z
CREATED:20160529T143451Z
......
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//K Desktop Environment//NONSGML KOrganizer 5.2.50 pre
BEGIN:VEVENT
DTSTAMP:20160529T143213Z
CREATED:20160529T143106Z
......
......@@ -27,7 +27,6 @@
#include <KCalCore/Event>
#include <KCalCore/Todo>
#include <KCalCore/ICalFormat>
#include <CalendarEvents/CalendarEventsPlugin>
......
......@@ -23,7 +23,7 @@
FakePimDataSource::FakePimDataSource()
: PimDataSource()
, mCalendar(new KCalCore::MemoryCalendar(KDateTime::UTC))
, mCalendar(new KCalCore::MemoryCalendar(KDateTime::LocalZone))
{
}
......
......@@ -28,6 +28,7 @@
#include <QtTest/QTest>
#include <KCalCore/ICalFormat>
#include <KCalCore/MemoryCalendar>
#include <CalendarEvents/CalendarEventsPlugin>
......@@ -82,7 +83,7 @@ QDateTime TestDataParser::parseDateTime(const QJsonObject &dateTime)
{
return QDateTime(QDate::fromString(dateTime[QStringLiteral("date")].toString(), Qt::ISODate),
QTime::fromString(dateTime[QStringLiteral("time")].toString(), Qt::ISODate),
QTimeZone(dateTime[QStringLiteral("tz")].toString().toLatin1()));
QTimeZone(dateTime[QStringLiteral("tz")].toString().toLatin1())).toLocalTime();
}
void TestDataParser::parse()
......@@ -91,9 +92,11 @@ void TestDataParser::parse()
QVERIFY(icalFile.exists());
QVERIFY(icalFile.open(QIODevice::ReadOnly));
const QByteArray data = icalFile.readAll();
auto calendar = KCalCore::MemoryCalendar::Ptr::create(KDateTime::LocalZone);
KCalCore::ICalFormat format;
mIncidence = format.readIncidence(data);
QVERIFY(format.load(calendar, icalFile.fileName()));
QVERIFY(!calendar->incidences().isEmpty());
mIncidence = calendar->incidences().at(0);
QVERIFY(mIncidence);
QFile jsonFile(QStringLiteral(PIMEVENT_DATADIR "/data/%1.json").arg(mTestData));
......@@ -121,9 +124,15 @@ void TestDataParser::parse()
}
eventData.setIsAllDay(obj[QStringLiteral("allDay")].toBool());
eventData.setIsMinor(obj[QStringLiteral("isMinor")].toBool());
const QDateTime startDateTime = parseDateTime(obj[QStringLiteral("startDateTime")].toObject());
QDateTime startDateTime = parseDateTime(obj[QStringLiteral("startDateTime")].toObject());
if (eventData.isAllDay()) {
startDateTime.setTime(QTime(0, 0, 0, Qt::LocalTime));
}
eventData.setStartDateTime(startDateTime);
const QDateTime endDateTime = parseDateTime(obj[QStringLiteral("endDateTime")].toObject());
QDateTime endDateTime = parseDateTime(obj[QStringLiteral("endDateTime")].toObject());
if (eventData.isAllDay()) {
endDateTime.setTime(QTime(0, 0, 0, Qt::LocalTime));
}
eventData.setEndDateTime(endDateTime);
eventData.setUid(obj[QStringLiteral("uid")].toString());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment