diff --git a/tba-unit-tests/Extensions/Date+TBA_Tests.swift b/tba-unit-tests/Extensions/Date+TBA_Tests.swift index 049cb700e..86f582526 100644 --- a/tba-unit-tests/Extensions/Date+TBA_Tests.swift +++ b/tba-unit-tests/Extensions/Date+TBA_Tests.swift @@ -33,6 +33,12 @@ class DateTBATestCase: XCTestCase { XCTAssertFalse(epoch.isBetween(date: now, andDate: oneHourAgo)) } + func test_startOfDay() { + let calendar = Calendar.current + let today = calendar.date(bySettingHour: 0, minute: 0, second: 0, of: Date())! + XCTAssertEqual(Date().startOfDay(), today) + } + func test_endOfDay() { let calendar = Calendar.current let today = calendar.date(bySettingHour: 0, minute: 0, second: 0, of: Date())! diff --git a/the-blue-alliance-ios/Extensions/Date+TBA.swift b/the-blue-alliance-ios/Extensions/Date+TBA.swift index 120005107..797de1aff 100644 --- a/the-blue-alliance-ios/Extensions/Date+TBA.swift +++ b/the-blue-alliance-ios/Extensions/Date+TBA.swift @@ -17,6 +17,13 @@ extension Date { return calendar.date(byAdding: DateComponents(month: 1, day: -1), to: self.startOfMonth())! } + /** + 00:00:00am on the reciving date. + */ + func startOfDay(calendar: Calendar = Calendar.current) -> Date { + return calendar.date(bySettingHour: 0, minute: 0, second: 0, of: self)! + } + /** 11:59:59pm on the reciving date - used to inclusively match date in date logic */ diff --git a/the-blue-alliance-ios/View Controllers/Events/WeekEventsViewController.swift b/the-blue-alliance-ios/View Controllers/Events/WeekEventsViewController.swift index 95cbaccd4..8b1aa784a 100644 --- a/the-blue-alliance-ios/View Controllers/Events/WeekEventsViewController.swift +++ b/the-blue-alliance-ios/View Controllers/Events/WeekEventsViewController.swift @@ -135,7 +135,7 @@ class WeekEventsViewController: EventsViewController { func setupCurrentSeasonWeek() { // Fetch all events where endDate is today or after today - let coreDataDate = NSDate(timeIntervalSince1970: Date().endOfDay().timeIntervalSince1970) + let coreDataDate = NSDate(timeIntervalSince1970: Date().startOfDay().timeIntervalSince1970) // Find the first non-finished event for the selected year let event = Event.fetchSingleObject(in: persistentContainer.viewContext) { (fetchRequest) in