Skip to content

Instantly share code, notes, and snippets.

@beccadax
Last active September 9, 2016 20:44
Show Gist options
  • Save beccadax/11b3275424d0833cfd99 to your computer and use it in GitHub Desktop.
Save beccadax/11b3275424d0833cfd99 to your computer and use it in GitHub Desktop.
Some important NSDate extensions
extension NSDate: Comparable {}
public func < (lhs: NSDate, rhs: NSDate) -> Bool {
return lhs.compare(rhs) == .OrderedAscending
}
// Gets you NSDate + NSTimeInterval, NSDate - NSTimeInterval, and NSDate - NSDate.
extension NSDate: Strideable {
public func advancedBy(n: NSTimeInterval) -> Self {
return dateByAddingTimeInterval(n)
}
public func distanceTo(other: NSDate) -> NSTimeInterval {
return other.timeIntervalSinceDate(self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment