Skip to content

Commit

Permalink
fix(calendar): adjust invalid dates when importing a vEvent
Browse files Browse the repository at this point in the history
Fixes #4845
  • Loading branch information
cgx committed Dec 16, 2019
1 parent a25e5ac commit 15d7c69
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions SoObjects/Appointments/iCalEvent+SOGo.m
Expand Up @@ -475,7 +475,7 @@ - (iCalTimeZone *) adjustInContext: (WOContext *) context
[self setStartDate: date];
}
startDate = (iCalDateTime *) [self uniqueChildWithTag: @"dtstart"];
[self errorWithFormat: @"Fixed event with no start date; setting start date to %@ for UID %@", [startDate dateTime], [self uid]];
[self errorWithFormat: @"Event with no start date; setting start date to %@ for UID %@", [startDate dateTime], [self uid]];
}

if ([startDate dateTime])
Expand All @@ -488,8 +488,9 @@ - (iCalTimeZone *) adjustInContext: (WOContext *) context
else
{
startDateAsString = [[startDate valuesAtIndex: 0 forKey: @""] objectAtIndex: 0];
if (![startDateAsString hasSuffix: @"Z"] &&
![startDateAsString hasSuffix: @"z"])
if (!([self isAllDay] ||
[startDateAsString hasSuffix: @"Z"] ||
[startDateAsString hasSuffix: @"z"]))
{
// The start date is a "floating time", let's use the user's timezone
// for both the start and end dates.
Expand All @@ -499,11 +500,13 @@ - (iCalTimeZone *) adjustInContext: (WOContext *) context

[self setStartDate: [[self startDate] dateByAddingYears: 0 months: 0 days: 0 hours: 0 minutes: 0 seconds: -delta]];
[startDate setTimeZone: timezone];
[self errorWithFormat: @"Event with no timezone; setting timezone %@ to start date for UID %@", [timezone tzId], [self uid]];

if ([endDate dateTime])
{
[self setEndDate: [[self endDate] dateByAddingYears: 0 months: 0 days: 0 hours: 0 minutes: 0 seconds: -delta]];
[endDate setTimeZone: timezone];
[self errorWithFormat: @"Event with no timezone; setting timezone %@ to end date for UID %@", [timezone tzId], [self uid]];
}
}
}
Expand All @@ -517,7 +520,7 @@ - (iCalTimeZone *) adjustInContext: (WOContext *) context
else
[self setDuration: @"PT1H"];

[self errorWithFormat: @"Fixed event with no end date; setting duration to %@ for UID %@", [self duration], [self uid]];
[self errorWithFormat: @"Event with no end date; setting duration to %@ for UID %@", [self duration], [self uid]];
}

//
Expand All @@ -530,7 +533,7 @@ - (iCalTimeZone *) adjustInContext: (WOContext *) context
if ([self isAllDay] && [[self startDate] isEqual: [self endDate]])
{
[self setEndDate: [[self startDate] dateByAddingYears: 0 months: 0 days: 1 hours: 0 minutes: 0 seconds: 0]];
[self errorWithFormat: @"Fixed broken all-day event; setting end date to %@ for UID %@", [self endDate], [self uid]];
[self errorWithFormat: @"Broken all-day event; setting end date to %@ for UID %@", [self endDate], [self uid]];
}


Expand Down

0 comments on commit 15d7c69

Please sign in to comment.