From 9dd514d3c7ece2beba69e076a9a0d3addb849593 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Fri, 9 Jul 2021 11:25:27 -0400 Subject: [PATCH] Show meeting info ~5 minutes after the meeting starts. --- .../Events and Reminders/CalendarHandler.swift | 15 ++++++++++++++- Clocker/Panel/ParentPanelController.swift | 6 +----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Clocker/Events and Reminders/CalendarHandler.swift b/Clocker/Events and Reminders/CalendarHandler.swift index 80a4028..b095e5d 100644 --- a/Clocker/Events and Reminders/CalendarHandler.swift +++ b/Clocker/Events and Reminders/CalendarHandler.swift @@ -158,7 +158,7 @@ extension EventCenter { let relevantEvents = filteredEvents[autoupdatingCalendar.startOfDay(for: Date())] ?? [] let filteredEvent = relevantEvents.filter { - $0.event.isAllDay == false && $0.event.startDate.timeIntervalSinceNow > 0 + $0.event.isAllDay == false && $0.event.startDate.timeIntervalSinceNow > -300 }.first if let firstEvent = filteredEvent { @@ -424,4 +424,17 @@ struct EventInfo { let isAllDay: Bool let isSingleDay: Bool let meetingURL: URL? + + func metadataForMeeting() -> String { + let timeIntervalSinceNowForMeeting = event.startDate.timeIntervalSinceNow + if (timeIntervalSinceNowForMeeting < 0 && timeIntervalSinceNowForMeeting > -300) { + return "Event began \(event.startDate.shortTimeAgoSinceNow) ago." + } else { + let timeSince = Date().timeAgo(since: event.startDate) + let withoutAn = timeSince.replacingOccurrences(of: "an", with: CLEmptyString) + let withoutAgo = withoutAn.replacingOccurrences(of: "ago", with: CLEmptyString) + + return "in \(withoutAgo.lowercased())" + } + } } diff --git a/Clocker/Panel/ParentPanelController.swift b/Clocker/Panel/ParentPanelController.swift index d8f72b3..f9c960e 100644 --- a/Clocker/Panel/ParentPanelController.swift +++ b/Clocker/Panel/ParentPanelController.swift @@ -840,11 +840,7 @@ class ParentPanelController: NSWindowController { return } - let timeSince = Date().timeAgo(since: upcomingEvent.event.startDate) - let withoutAn = timeSince.replacingOccurrences(of: "an", with: CLEmptyString) - let withoutAgo = withoutAn.replacingOccurrences(of: "ago", with: CLEmptyString) - - self.setCalendarButtonTitle(buttonTitle: "in \(withoutAgo.lowercased())") + self.setCalendarButtonTitle(buttonTitle: upcomingEvent.metadataForMeeting()) if upcomingEvent.meetingURL != nil { self.whiteRemoveButton.image = Themer.shared().videoCallImage()