diff --git a/PadelClubData/Data/Event.swift b/PadelClubData/Data/Event.swift index 491d253..33c97e6 100644 --- a/PadelClubData/Data/Event.swift +++ b/PadelClubData/Data/Event.swift @@ -183,7 +183,35 @@ final public class Event: BaseEvent { return link.compactMap({ $0 }).joined(separator: "\n\n") } + + public func selectedTeams() -> [TeamRegistration] { + confirmedTournaments().flatMap({ $0.selectedSortedTeams() }) + } + public func umpireMail() -> [String]? { + confirmedTournaments().first?.umpireMail() + } + + public func mailSubject() -> String { + let tournaments = confirmedTournaments() + + guard !tournaments.isEmpty else { + return eventTitle() + } + + // Get the date range from all confirmed tournaments + let dates = tournaments.compactMap { $0.startDate } + guard let firstDate = dates.min(), let lastDate = dates.max() else { + return eventTitle() + } + + let dateRange = firstDate == lastDate + ? firstDate.formattedDate(.short) + : "\(firstDate.formattedDate(.short)) - \(lastDate.formattedDate(.short))" + + let subject = [eventTitle(), dateRange, clubObject()?.name].compactMap({ $0 }).joined(separator: " | ") + return subject + } func insertOnServer() throws { DataStore.shared.events.writeChangeAndInsertOnServer(instance: self) diff --git a/PadelClubData/Data/Tournament.swift b/PadelClubData/Data/Tournament.swift index f421757..ab4a221 100644 --- a/PadelClubData/Data/Tournament.swift +++ b/PadelClubData/Data/Tournament.swift @@ -1216,14 +1216,7 @@ defer { } public func formattedDate(_ displayStyle: DisplayStyle = .wide) -> String { - switch displayStyle { - case .title: - startDate.formatted(.dateTime.weekday(.abbreviated).day().month(.abbreviated).year()) - case .wide: - startDate.formatted(date: Date.FormatStyle.DateStyle.complete, time: Date.FormatStyle.TimeStyle.omitted) - case .short: - startDate.formatted(date: .numeric, time: .omitted) - } + startDate.formattedDate(displayStyle) } public func qualifiedFromGroupStage() -> Int { diff --git a/PadelClubData/Extensions/Date+Extensions.swift b/PadelClubData/Extensions/Date+Extensions.swift index aa681c4..035fc1b 100644 --- a/PadelClubData/Extensions/Date+Extensions.swift +++ b/PadelClubData/Extensions/Date+Extensions.swift @@ -311,6 +311,18 @@ public extension Date { let calendar = Calendar.current return calendar.date(bySetting: .minute, value: 0, of: self)!.withoutSeconds() } + + func formattedDate(_ displayStyle: DisplayStyle = .wide) -> String { + switch displayStyle { + case .title: + self.formatted(.dateTime.weekday(.abbreviated).day().month(.abbreviated).year()) + case .wide: + self.formatted(date: Date.FormatStyle.DateStyle.complete, time: Date.FormatStyle.TimeStyle.omitted) + case .short: + self.formatted(date: .numeric, time: .omitted) + } + } + } public extension Date {