diff --git a/KNContacts/KNContact.swift b/KNContacts/KNContact.swift index 550a689..f97c9ff 100644 --- a/KNContacts/KNContact.swift +++ b/KNContacts/KNContact.swift @@ -179,7 +179,7 @@ public struct KNContact { - Author: dragosrobertn - Parameters: - in: The number of days as an integer representing the number of days to check if the birthday is upcoming - - startingDate: The date from which to start checking if the birthday is upcoming. Default is today's date. + - startingDate: The date from which to start checking if the birthday is upcoming. Default is today's date and the starting date will be excluded.. - Returns: Returns a bool representing whether the today is the contact's birthday. False if the contact doesn't have birthday information available. - Version: 1.2.1 @@ -187,7 +187,7 @@ public struct KNContact { public func isBirthdayComing(in days: Int, startingDate: Date = Date()) -> Bool { guard let birthday = self.getBirthday(forCurrentYear: true) else { return false } let birthdayComponents = calendar.dateComponents([.day, .month], from: birthday) - let dateComponents: [DateComponents] = (0...days) + let dateComponents: [DateComponents] = (1...days) .compactMap({ number in return calendar.date(byAdding: .day, value: number, to: startingDate)! }) .compactMap({ date in return calendar.dateComponents([.day, .month], from: date)}) diff --git a/KNContactsTests/KNContactTests.swift b/KNContactsTests/KNContactTests.swift index dadb6ce..f660f26 100644 --- a/KNContactsTests/KNContactTests.swift +++ b/KNContactsTests/KNContactTests.swift @@ -126,6 +126,18 @@ class KNContactTests: XCTestCase { XCTAssertFalse(contact.isBirthdayComing(in: 7)) } + func testIsBirthdayComingIsFalseWhenBirthdayIsToday() { + let mutableContact = UnitTestsContactHelpers.getMutableContact() + + let todayComponents = calendar.dateComponents([.day, .month], from: Date()) + mutableContact.birthday?.day = todayComponents.day + mutableContact.birthday?.month = todayComponents.month + + let contact = KNContact(for: mutableContact) + + XCTAssertFalse(contact.isBirthdayComing(in: 7)) + } + func testIsBirthdayComingIsTrue() { let mutableContact = UnitTestsContactHelpers.getMutableContact() let aWeekFromToday = calendar.date(byAdding: .day, value: 7, to: Date())! @@ -157,7 +169,7 @@ class KNContactTests: XCTestCase { func testIsBirthdayComingIsTrueForContactWithBirthdayInLateDecemberWhichMakesTheCheckPassAYear() { let mutableContact = UnitTestsContactHelpers.getMutableContact() - mutableContact.birthday?.day = 27 + mutableContact.birthday?.day = 28 mutableContact.birthday?.month = 12 let dateUtilsFormatter = KNDatesUtils.formatter(with: .fullDate) @@ -169,7 +181,7 @@ class KNContactTests: XCTestCase { func testIsBirthdayComingIsFalseForContactWithBirthdayInLateDecemberThatJustPassedWhichMakesTheCheckPassAYear() { let mutableContact = UnitTestsContactHelpers.getMutableContact() - mutableContact.birthday?.day = 26 + mutableContact.birthday?.day = 27 mutableContact.birthday?.month = 12 let dateUtilsFormatter = KNDatesUtils.formatter(with: .fullDate)