Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/swift/Time.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,16 @@ public func -(time: DispatchTime, interval: DispatchTimeInterval) -> DispatchTim
}

public func +(time: DispatchTime, seconds: Double) -> DispatchTime {
let t = CDispatch.dispatch_time(time.rawValue, Int64(seconds * Double(NSEC_PER_SEC)))
let interval = seconds * Double(NSEC_PER_SEC)
let t = CDispatch.dispatch_time(time.rawValue,
interval.isInfinite || interval.isNaN ? Int64.max : Int64(interval))
return DispatchTime(rawValue: t)
}

public func -(time: DispatchTime, seconds: Double) -> DispatchTime {
let t = CDispatch.dispatch_time(time.rawValue, Int64(-seconds * Double(NSEC_PER_SEC)))
let interval = -seconds * Double(NSEC_PER_SEC)
let t = CDispatch.dispatch_time(time.rawValue,
interval.isInfinite || interval.isNaN ? Int64.min : Int64(interval))
return DispatchTime(rawValue: t)
}

Expand All @@ -130,11 +134,15 @@ public func -(time: DispatchWallTime, interval: DispatchTimeInterval) -> Dispatc
}

public func +(time: DispatchWallTime, seconds: Double) -> DispatchWallTime {
let t = CDispatch.dispatch_time(time.rawValue, Int64(seconds * Double(NSEC_PER_SEC)))
let interval = seconds * Double(NSEC_PER_SEC)
let t = CDispatch.dispatch_time(time.rawValue,
interval.isInfinite || interval.isNaN ? Int64.max : Int64(interval))
return DispatchWallTime(rawValue: t)
}

public func -(time: DispatchWallTime, seconds: Double) -> DispatchWallTime {
let t = CDispatch.dispatch_time(time.rawValue, Int64(-seconds * Double(NSEC_PER_SEC)))
let interval = seconds * Double(NSEC_PER_SEC)
let t = CDispatch.dispatch_time(time.rawValue,
interval.isInfinite || interval.isNaN ? Int64.min : Int64(interval))
return DispatchWallTime(rawValue: t)
}