Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed passing wrong offset value for comparing few DateComparisonType #124

Merged
merged 1 commit into from
Mar 20, 2024

Conversation

iranjith4
Copy link
Contributor

When comparing yesterday's date with .compare(.isTomorrow), the function is returning true which is wrong.

Example:

let date = Date()
let tomorrow = date.offset(.day, value: 1)!
let yesterday = date.offset(.day, value: -1)!

//In version 5.0.1, these comparison returns `true`, which is a bug. 

if tomorrow.compare(.isYesterday) { 
    print(".isYesterday COMPARISION WRONG")
}

if yesterday.compare(.isTomorrow) {
    print(".isTomorrow COMPARISION WRONG")
}

The same happens for comparing the following DateComparisonType

isYesterday, isTomorrow, isLastWeek, isNextWeek, isLastMonth, isNextMonth, isLastYear, isNextYear 

Changes:

Bug:
During the comparison of the date, the offset for .isSameDay was passed based on the difference between Date() and self, which is a bug.

Fix:
Fixed it by passing the offset value calculated based on the DateComparisonType.

Fixed passing `offset` value that is calculated based on the current date and given date. The offset to compare should correspond to the `DateComparisonType`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants