Skip to content

Commit

Permalink
Extensions/DispatchTimeInterval: Add DispatchTimeInterval+Comparable
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyl committed May 27, 2024
1 parent 75919f3 commit e872cf6
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Cornucopia – (C) Dr. Lauer Information Technology
//
import Foundation

extension DispatchTimeInterval: Comparable {

var CC_nanoseconds: UInt64 {
switch self {
case let .seconds(s): UInt64(s) * UInt64(1_000_000_000)
case let .milliseconds(ms): UInt64(ms) * UInt64(1_000_000)
case let .microseconds(ms): UInt64(ms) * UInt64(1000)
case let .nanoseconds(ns): UInt64(ns)
case .never: UInt64.max
@unknown default: fatalError("Unknown value: \(self)")
}
}

public static func < (lhs: DispatchTimeInterval, rhs: DispatchTimeInterval) -> Bool { lhs.CC_nanoseconds < rhs.CC_nanoseconds }
}

0 comments on commit e872cf6

Please sign in to comment.