Created
December 27, 2016 11:39
-
-
Save ushpizin/d6dc4af7994a6d2366381b32196b2afa to your computer and use it in GitHub Desktop.
Comparable extension of DateComponents
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
| // | |
| // DateComponents+Comparable.swift | |
| // | |
| // Created by Liran on 27/12/2016. | |
| // License: MIT | |
| // | |
| import Foundation | |
| extension DateComponents: Comparable { | |
| public static func < (lhs: DateComponents, rhs: DateComponents) -> Bool { | |
| guard let lhsDate = Calendar.current.date(from: lhs), | |
| let rhsDate = Calendar.current.date(from: rhs) else { | |
| assertionFailure("A date which matches the components couldn't be found") | |
| return false | |
| } | |
| return lhsDate < rhsDate | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment