-
-
Save krin-san/ef7d43061cfe64ce1d89 to your computer and use it in GitHub Desktop.
Swift NSDate Comparison Extension
This file contains hidden or 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
// NSDate doesn't include overrides for standard comparison operators in Swift. | |
// This extension adds <, >, <=, >=, and ==, using NSDate's built-in `compare` method. | |
// MIT licensed. | |
func <=(lhs: NSDate, rhs: NSDate) -> Bool { | |
return lhs.compare(rhs) != .OrderedDescending | |
} | |
func >=(lhs: NSDate, rhs: NSDate) -> Bool { | |
return lhs.compare(rhs) != .OrderedAscending | |
} | |
func >(lhs: NSDate, rhs: NSDate) -> Bool { | |
return lhs.compare(rhs) == .OrderedDescending | |
} | |
func <(lhs: NSDate, rhs: NSDate) -> Bool { | |
return lhs.compare(rhs) == .OrderedAscending | |
} | |
func ==(lhs: NSDate, rhs: NSDate) -> Bool { | |
return lhs.compare(rhs) == .OrderedSame | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment