Skip to content

Commit 144b938

Browse files
committed
Remove the DispatchTimeInterval extension that adds asSeconds and instead make the similar one in Basics public and use it, based on review feedback.
1 parent 4b0827c commit 144b938

File tree

2 files changed

+5
-22
lines changed

2 files changed

+5
-22
lines changed

Sources/Basics/DispatchTimeInterval+Extensions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2020 Apple Inc. and the Swift project authors
4+
Copyright (c) 2020-2022 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
@@ -12,7 +12,7 @@ import Dispatch
1212
import struct Foundation.TimeInterval
1313

1414
extension DispatchTimeInterval {
15-
func timeInterval() -> TimeInterval? {
15+
public func timeInterval() -> TimeInterval? {
1616
switch self {
1717
case .seconds(let value):
1818
return Double(value)
@@ -27,7 +27,7 @@ extension DispatchTimeInterval {
2727
}
2828
}
2929

30-
func milliseconds() -> Int? {
30+
public func milliseconds() -> Int? {
3131
switch self {
3232
case .seconds(let value):
3333
return value.multipliedReportingOverflow(by: 1000).partialValue
@@ -42,7 +42,7 @@ extension DispatchTimeInterval {
4242
}
4343
}
4444

45-
func seconds() -> Int? {
45+
public func seconds() -> Int? {
4646
switch self {
4747
case .seconds(let value):
4848
return value

Sources/Commands/SwiftTestTool.swift

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ extension SwiftTestTool {
11981198
// Run the test — for now we run the sequentially so we can capture accurate timing results.
11991199
let startTime = DispatchTime.now()
12001200
let (success, _) = testRunner.test(writeToOutputStream: false)
1201-
let duration = startTime.distance(to: .now()).asSeconds ?? 0.0
1201+
let duration = Double(startTime.distance(to: .now()).milliseconds() ?? 0) / 1000.0
12021202
numFailedTests += success ? 0 : 1
12031203
testResults.append(.init(name: testName, result: success ? .succeeded : .failed, duration: duration))
12041204
}
@@ -1261,20 +1261,3 @@ extension SwiftTestTool {
12611261
codeCoverageDataFile: codeCoverageDataFile?.pathString)
12621262
}
12631263
}
1264-
1265-
fileprivate extension DispatchTimeInterval {
1266-
var asSeconds: Double? {
1267-
switch self {
1268-
case .seconds(let value):
1269-
return Double(value)
1270-
case .milliseconds(let value):
1271-
return Double(value) / 1000
1272-
case .microseconds(let value):
1273-
return Double(value) / 1_000_000
1274-
case .nanoseconds(let value):
1275-
return Double(value) / 1_000_000_000
1276-
default:
1277-
return .none
1278-
}
1279-
}
1280-
}

0 commit comments

Comments
 (0)