Skip to content

Commit

Permalink
Fix early week switching (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachOrr authored Apr 20, 2019
1 parent 4f89c76 commit 1060785
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions tba-unit-tests/Extensions/Date+TBA_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())!
Expand Down
7 changes: 7 additions & 0 deletions the-blue-alliance-ios/Extensions/Date+TBA.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1060785

Please sign in to comment.