fix(calendar): adjust invalid dates when importing a vEvent

Fixes #4845
pull/265/head
Francis Lachapelle 2019-12-16 10:48:26 -05:00
parent a25e5acba4
commit 15d7c69d94
1 changed files with 8 additions and 5 deletions

View File

@ -475,7 +475,7 @@
[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])
@ -488,8 +488,9 @@
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.
@ -499,11 +500,13 @@
[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]];
}
}
}
@ -517,7 +520,7 @@
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]];
}
//
@ -530,7 +533,7 @@
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]];
}