melvitax / DateHelper

A Swift Date extension helper
MIT License
1.5k stars 242 forks source link

Comparing with .isTomorrow, .isYesterday, .isLastWeek.. etc is giving wrong value #125

Open iranjith4 opened 7 months ago

iranjith4 commented 7 months ago

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 
iranjith4 commented 7 months ago

Raised a PR #124 with a fix.