Skip to content

Instantly share code, notes, and snippets.

@krin-san
Forked from psobot/NSDate+Extensions.swift
Last active August 23, 2016 08:51
Show Gist options
  • Save krin-san/ef7d43061cfe64ce1d89 to your computer and use it in GitHub Desktop.
Save krin-san/ef7d43061cfe64ce1d89 to your computer and use it in GitHub Desktop.
Swift NSDate Comparison Extension
// 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