Treat a whole-day span as all-day, whatever the payload claims
The previous rule only caught date-only strings. A multi-day event sent with full timestamps and no allDay flag still arrived as a timed event, so a holiday running from the 16th to the 21st rendered as a one-hour slot at midnight. Now an event that starts and ends on a day boundary and covers at least one whole day is all-day regardless. That is a statement about what the data means, not about how any one client formats it, which is why it lives in the parser and not in a view. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
6e91eaaaa2
commit
465c465af2
@@ -98,11 +98,21 @@ struct CalEvent: Identifiable, Hashable {
|
|||||||
let clean = startStr.trimmingCharacters(in: .whitespaces)
|
let clean = startStr.trimmingCharacters(in: .whitespaces)
|
||||||
return clean.count == 10 && !clean.contains("T")
|
return clean.count == 10 && !clean.contains("T")
|
||||||
}()
|
}()
|
||||||
let isAllDay = (json["allDay"] as? Bool ?? false) || startIsDateOnly
|
let declaredAllDay = (json["allDay"] as? Bool ?? false) || startIsDateOnly
|
||||||
let startDate = parseDate(startStr, allDay: isAllDay)
|
let startDate = parseDate(startStr, allDay: declaredAllDay)
|
||||||
let endDate = parseDate(endStr, allDay: isAllDay)
|
let endDate = parseDate(endStr, allDay: declaredAllDay)
|
||||||
guard let s = startDate, let e = endDate else { return nil }
|
guard let s = startDate, let e = endDate else { return nil }
|
||||||
|
|
||||||
|
// An event running midnight to midnight across one or more whole days
|
||||||
|
// is all-day whatever the payload claims. Without this, a six-day
|
||||||
|
// holiday sent without the flag renders as "00:00 – 00:00" — a time
|
||||||
|
// range that is technically true and tells the reader nothing.
|
||||||
|
let cal = Calendar.current
|
||||||
|
let spansWholeDays = e > s
|
||||||
|
&& cal.startOfDay(for: s) == s
|
||||||
|
&& cal.startOfDay(for: e) == e
|
||||||
|
let isAllDay = declaredAllDay || spansWholeDays
|
||||||
|
|
||||||
return CalEvent(
|
return CalEvent(
|
||||||
id: id,
|
id: id,
|
||||||
url: json["url"] as? String ?? "",
|
url: json["url"] as? String ?? "",
|
||||||
|
|||||||
Reference in New Issue
Block a user