Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions App/Services/Calendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ final class CalendarService: Service {
properties: [
"start": .string(
description:
"Start date/time of the range (defaults to now). If timezone is omitted, local time is assumed. Date-only uses local midnight.",
"Start date/time (defaults to now; if end is date-only and start is omitted, uses end's local midnight). If timezone is omitted, local time is assumed.",
format: .dateTime
),
"end": .string(
description:
"End date/time of the range (defaults to one week from start; one day if start is date-only). If timezone is omitted, local time is assumed. Date-only uses local midnight.",
"End date/time (defaults to one week from start; one day if start is date-only). If timezone is omitted, local time is assumed.",
format: .dateTime
),
"calendars": .array(
Expand Down Expand Up @@ -126,6 +126,7 @@ final class CalendarService: Service {
let calendar = Calendar.current
var startDate = now
var endDate = calendar.date(byAdding: .weekOfYear, value: 1, to: now)!
var hasStart = false
var hasEnd = false
var startIsDateOnly = false
var endIsDateOnly = false
Expand All @@ -135,6 +136,7 @@ final class CalendarService: Service {
fromISO8601String: start
)
{
hasStart = true
startDate = parsedStart.date
startIsDateOnly = parsedStart.isDateOnly
}
Expand All @@ -149,6 +151,11 @@ final class CalendarService: Service {
endIsDateOnly = parsedEnd.isDateOnly
}

if !hasStart, endIsDateOnly {
startDate = endDate
startIsDateOnly = true
}

startDate = calendar.normalizedStartDate(from: startDate, isDateOnly: startIsDateOnly)

if endIsDateOnly {
Expand Down