Last active
September 9, 2016 20:44
-
-
Save beccadax/11b3275424d0833cfd99 to your computer and use it in GitHub Desktop.
Some important NSDate extensions
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 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