-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extensions/DispatchTimeInterval: Add DispatchTimeInterval+Comparable
- Loading branch information
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
Sources/CornucopiaCore/Extensions/DispatchTimeInterval/DispatchTimeInterval+Comparable.swift
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
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 } | ||
} |