Skip to content

Commit

Permalink
[buteo-sync-plugins-social] Ensure Google Calendar allDay flag is set…
Browse files Browse the repository at this point in the history
… correctly. Contributes to JB#51406

Ensures that the "allDay" flag for an event is set in the case where the
start date is a date only (no time) and one of the following holds:

1. The start date and end date are the same (single day event).
2. The end date is one day after the start date (single day event).
3. Anything else (multi-day event).

In the case of 3, the end date is adjusted to account for the fact that
allDay events have exclusive, rather than inclusive, end dates.
  • Loading branch information
llewelld committed Oct 6, 2020
1 parent d26215a commit 66b0bd7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/google/google-calendars/googlecalendarsyncadaptor.cpp
Expand Up @@ -439,7 +439,8 @@ QJsonObject kCalToJson(KCalCore::Event::Ptr event, KCalCore::ICalFormat &icalFor
start.insert(QLatin1String("timeZone"), QJsonValue(event->dtStart().toString(KLONGTZ_FORMAT)));
}
if (event->dtEnd().isDateOnly() || (event->allDay() && event->dtEnd().time() == QTime(0,0,0))) {
end.insert(QLatin1String("date"), QLocale::c().toString(event->dateEnd(), QDATEONLY_FORMAT));
// For all day events, the end date is exclusive, so we need to add 1
end.insert(QLatin1String("date"), QLocale::c().toString(event->dateEnd().addDays(1), QDATEONLY_FORMAT));
} else {
end.insert(QLatin1String("dateTime"), event->dtEnd().toString(RFC3339_FORMAT));
end.insert(QLatin1String("timeZone"), QJsonValue(event->dtEnd().toString(KLONGTZ_FORMAT)));
Expand Down Expand Up @@ -603,7 +604,7 @@ void extractStartAndEnd(const QJsonObject &eventData,
// multi-day all-day event.
// as noted above, Google will send all-day events as having an end-date
// of real-end-date+1 in order to conform to iCal spec (exclusive end dt).
*end = KDateTime(QLocale::c().toDate(endTimeString, QDATEONLY_FORMAT), QTime(), KDateTime::ClockTime);
*end = KDateTime(QLocale::c().toDate(endTimeString, QDATEONLY_FORMAT).addDays(-1), QTime(), KDateTime::ClockTime);
end->setDateOnly(true);
*isAllDay = true;
}
Expand Down Expand Up @@ -890,7 +891,7 @@ void jsonToKCal(const QJsonObject &json, KCalCore::Event::Ptr event, int default
UPDATE_EVENT_PROPERTY_IF_REQUIRED(event, hasEndDate, setHasEndDate, false, changed)
}
if (isAllDay) {
UPDATE_EVENT_PROPERTY_IF_REQUIRED(event, allDay, setAllDay, false, changed)
UPDATE_EVENT_PROPERTY_IF_REQUIRED(event, allDay, setAllDay, true, changed)
}
extractAlarms(json, event, defaultReminderStartOffset, changed);
END_EVENT_UPDATES_IF_REQUIRED(event, changed, !alreadyStarted);
Expand Down

0 comments on commit 66b0bd7

Please sign in to comment.