Browse Source

Simplify EventInfo.

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
a7a371f914
  1. 15
      Clocker/ClockerUnitTests/EventInfoTests.swift
  2. 9
      Clocker/Events and Reminders/CalendarHandler.swift

15
Clocker/ClockerUnitTests/EventInfoTests.swift

@ -14,10 +14,7 @@ class EventInfoTests: XCTestCase {
mockEvent.startDate = Date().add(futureChunk) mockEvent.startDate = Date().add(futureChunk)
let mockEventInfo = EventInfo(event: mockEvent, let mockEventInfo = EventInfo(event: mockEvent,
isStartDate: false,
isEndDate: false,
isAllDay: false, isAllDay: false,
isSingleDay: true,
meetingURL: nil, meetingURL: nil,
attendeStatus: .accepted) attendeStatus: .accepted)
XCTAssert(mockEventInfo.metadataForMeeting() == "in 5m", XCTAssert(mockEventInfo.metadataForMeeting() == "in 5m",
@ -31,10 +28,7 @@ class EventInfoTests: XCTestCase {
mockEvent.startDate = Date().add(futureChunk) mockEvent.startDate = Date().add(futureChunk)
let mockEventInfo = EventInfo(event: mockEvent, let mockEventInfo = EventInfo(event: mockEvent,
isStartDate: false,
isEndDate: false,
isAllDay: false, isAllDay: false,
isSingleDay: true,
meetingURL: nil, meetingURL: nil,
attendeStatus: .accepted) attendeStatus: .accepted)
XCTAssert(mockEventInfo.metadataForMeeting() == "in <1m", XCTAssert(mockEventInfo.metadataForMeeting() == "in <1m",
@ -48,10 +42,7 @@ class EventInfoTests: XCTestCase {
mockEvent.startDate = Date().subtract(pastChunk) mockEvent.startDate = Date().subtract(pastChunk)
let mockEventInfo = EventInfo(event: mockEvent, let mockEventInfo = EventInfo(event: mockEvent,
isStartDate: false,
isEndDate: false,
isAllDay: false, isAllDay: false,
isSingleDay: true,
meetingURL: nil, meetingURL: nil,
attendeStatus: .accepted) attendeStatus: .accepted)
XCTAssert(mockEventInfo.metadataForMeeting() == "started +2m.", XCTAssert(mockEventInfo.metadataForMeeting() == "started +2m.",
@ -65,10 +56,7 @@ class EventInfoTests: XCTestCase {
mockEvent.startDate = Date().subtract(pastChunk) mockEvent.startDate = Date().subtract(pastChunk)
let mockEventInfo = EventInfo(event: mockEvent, let mockEventInfo = EventInfo(event: mockEvent,
isStartDate: false,
isEndDate: false,
isAllDay: false, isAllDay: false,
isSingleDay: true,
meetingURL: nil, meetingURL: nil,
attendeStatus: .accepted) attendeStatus: .accepted)
XCTAssert(mockEventInfo.metadataForMeeting() == "Error", XCTAssert(mockEventInfo.metadataForMeeting() == "Error",
@ -82,10 +70,7 @@ class EventInfoTests: XCTestCase {
mockEvent.startDate = Date().add(pastChunk) mockEvent.startDate = Date().add(pastChunk)
let mockEventInfo = EventInfo(event: mockEvent, let mockEventInfo = EventInfo(event: mockEvent,
isStartDate: false,
isEndDate: false,
isAllDay: false, isAllDay: false,
isSingleDay: true,
meetingURL: nil, meetingURL: nil,
attendeStatus: .accepted) attendeStatus: .accepted)
XCTAssert(mockEventInfo.metadataForMeeting() == "in 25h", XCTAssert(mockEventInfo.metadataForMeeting() == "in 25h",

9
Clocker/Events and Reminders/CalendarHandler.swift

@ -362,17 +362,11 @@ extension EventCenter {
private func generateEventInfo(for event: EKEvent, _ date: Date, _ nextDate: Date) -> EventInfo { private func generateEventInfo(for event: EKEvent, _ date: Date, _ nextDate: Date) -> EventInfo {
// Make a customized struct // Make a customized struct
let isStartDate = autoupdatingCalendar.isDate(date, inSameDayAs: event.startDate) && (event.endDate.compare(date) == .orderedDescending)
let isEndDate = autoupdatingCalendar.isDate(date, inSameDayAs: event.endDate) && (event.startDate.compare(date) == .orderedAscending)
let isAllDay = event.isAllDay || (event.startDate.compare(date) == .orderedAscending && event.endDate.compare(nextDate) == .orderedSame) let isAllDay = event.isAllDay || (event.startDate.compare(date) == .orderedAscending && event.endDate.compare(nextDate) == .orderedSame)
let isSingleDay = event.isAllDay && (event.startDate.compare(date) == .orderedSame && event.endDate.compare(nextDate) == .orderedSame)
let eventParticipationStatus = attendingStatusForUser(event) let eventParticipationStatus = attendingStatusForUser(event)
let meetingURL = retrieveMeetingURL(event) let meetingURL = retrieveMeetingURL(event)
let eventInfo = EventInfo(event: event, let eventInfo = EventInfo(event: event,
isStartDate: isStartDate,
isEndDate: isEndDate,
isAllDay: isAllDay, isAllDay: isAllDay,
isSingleDay: isSingleDay,
meetingURL: meetingURL, meetingURL: meetingURL,
attendeStatus: eventParticipationStatus) attendeStatus: eventParticipationStatus)
return eventInfo return eventInfo
@ -481,10 +475,7 @@ struct CalendarInfo {
struct EventInfo { struct EventInfo {
let event: EKEvent let event: EKEvent
let isStartDate: Bool
let isEndDate: Bool
let isAllDay: Bool let isAllDay: Bool
let isSingleDay: Bool
let meetingURL: URL? let meetingURL: URL?
let attendeStatus: EKParticipantStatus let attendeStatus: EKParticipantStatus

Loading…
Cancel
Save