Skip to content

Instantly share code, notes, and snippets.

@ushpizin
Created December 27, 2016 11:39
Show Gist options
  • Select an option

  • Save ushpizin/d6dc4af7994a6d2366381b32196b2afa to your computer and use it in GitHub Desktop.

Select an option

Save ushpizin/d6dc4af7994a6d2366381b32196b2afa to your computer and use it in GitHub Desktop.
Comparable extension of DateComponents
//
// 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