Skip to content

Commit 87bed5d

Browse files
committed
[Dispatch] Make comparisons with distantFuture work as expected
1 parent cc83fa6 commit 87bed5d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

stdlib/public/SDK/Dispatch/Time.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public struct DispatchTime : Comparable {
4545
}
4646

4747
public func <(a: DispatchTime, b: DispatchTime) -> Bool {
48-
if a.rawValue == ~0 || b.rawValue == ~0 { return false }
4948
return a.rawValue < b.rawValue
5049
}
5150

@@ -73,7 +72,11 @@ public struct DispatchWallTime : Comparable {
7372
}
7473

7574
public func <(a: DispatchWallTime, b: DispatchWallTime) -> Bool {
76-
if a.rawValue == ~0 || b.rawValue == ~0 { return false }
75+
if b.rawValue == ~0 {
76+
return a.rawValue != ~0
77+
} else if a.rawValue == ~0 {
78+
return false
79+
}
7780
return -Int64(bitPattern: a.rawValue) < -Int64(bitPattern: b.rawValue)
7881
}
7982

test/stdlib/Dispatch.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ DispatchAPI.test("dispatch_data_t deallocator") {
8989
DispatchAPI.test("DispatchTime comparisons") {
9090
do {
9191
let now = DispatchTime.now()
92-
checkComparable([now, now + .milliseconds(1)], oracle: {
92+
checkComparable([now, now + .milliseconds(1), .distantFuture], oracle: {
9393
return $0 < $1 ? .lt : $0 == $1 ? .eq : .gt
9494
})
9595
}
9696

9797
do {
9898
let now = DispatchWallTime.now()
99-
checkComparable([now, now + .milliseconds(1)], oracle: {
99+
checkComparable([now, now + .milliseconds(1), .distantFuture], oracle: {
100100
return $0 < $1 ? .lt : $0 == $1 ? .eq : .gt
101101
})
102102
}

0 commit comments

Comments
 (0)