Last active
March 17, 2017 14:18
-
-
Save JKalash/f29cb4be710cd5f090ff5b7fda294e11 to your computer and use it in GitHub Desktop.
isToday var for Date struct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Date { | |
var isToday : Bool { | |
let cal = Calendar.current | |
var components = cal.dateComponents([.era, .year, .month, .day], from: Date()) | |
let today = cal.date(from: components)! | |
components = cal.dateComponents([.era, .year, .month, .day], from: self) | |
let thisDate = cal.date(from: components)! | |
return (today as NSDate).isEqual(to: thisDate) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment