Skip to content

Instantly share code, notes, and snippets.

@dfelber
Last active August 26, 2016 06:58
Show Gist options
  • Save dfelber/e7baa7958a861a870dbd567c0d8253bb to your computer and use it in GitHub Desktop.
Save dfelber/e7baa7958a861a870dbd567c0d8253bb to your computer and use it in GitHub Desktop.
Compare NSDate with comparison operators
public func <(a: NSDate, b: NSDate) -> Bool {
return a.compare(b) == NSComparisonResult.OrderedAscending
}
public func >(a: NSDate, b: NSDate) -> Bool {
return a.compare(b) == NSComparisonResult.OrderedDescending
}
public func ==(a: NSDate, b: NSDate) -> Bool {
return a.compare(b) == NSComparisonResult.OrderedSame
}
public func >=(a: NSDate, b: NSDate) -> Bool {
return a > b || a == b
}
public func <=(a: NSDate, b: NSDate) -> Bool {
return a < b || a == b
}
extension NSDate: Comparable {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment