Skip to content

Commit 3c64d2b

Browse files
authored
Adopt SuspendingClock.systemEpoch. (#1202)
This PR adopts the new `systemEpoch` API added with [SE-0473](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0473-clock-epochs.md). This API is back-deployed, so we don't need availability annotations on Darwin. It is not available with the 6.1 toolchain though, so the old `unsafeBitCast()` calls remain if building from source with a 6.1 toolchain. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 64e1f9d commit 3c64d2b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Sources/Testing/Events/TimeValue.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ struct TimeValue: Sendable {
5454

5555
@available(_clockAPI, *)
5656
init(_ instant: SuspendingClock.Instant) {
57+
#if compiler(>=6.2)
58+
self.init(SuspendingClock().systemEpoch.duration(to: instant))
59+
#else
5760
self.init(unsafeBitCast(instant, to: Duration.self))
61+
#endif
5862
}
5963
}
6064

@@ -110,7 +114,11 @@ extension Duration {
110114
@available(_clockAPI, *)
111115
extension SuspendingClock.Instant {
112116
init(_ timeValue: TimeValue) {
117+
#if compiler(>=6.2)
118+
self = SuspendingClock().systemEpoch.advanced(by: Duration(timeValue))
119+
#else
113120
self = unsafeBitCast(Duration(timeValue), to: SuspendingClock.Instant.self)
121+
#endif
114122
}
115123
}
116124

0 commit comments

Comments
 (0)