melvitax / DateHelper

A Swift Date extension helper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

iranjith4 opened this issue · comments

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 

Raised a PR #124 with a fix.