From f4dc223c2f527bca318e411b7aace3e0d7d96134 Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Mon, 7 Jul 2025 12:19:03 -0400 Subject: [PATCH] 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. --- Sources/Testing/Events/TimeValue.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/Testing/Events/TimeValue.swift b/Sources/Testing/Events/TimeValue.swift index 5dac1fe08..143aa7091 100644 --- a/Sources/Testing/Events/TimeValue.swift +++ b/Sources/Testing/Events/TimeValue.swift @@ -54,7 +54,11 @@ struct TimeValue: Sendable { @available(_clockAPI, *) init(_ instant: SuspendingClock.Instant) { +#if compiler(>=6.2) + self.init(SuspendingClock().systemEpoch.duration(to: instant)) +#else self.init(unsafeBitCast(instant, to: Duration.self)) +#endif } } @@ -110,7 +114,11 @@ extension Duration { @available(_clockAPI, *) extension SuspendingClock.Instant { init(_ timeValue: TimeValue) { +#if compiler(>=6.2) + self = SuspendingClock().systemEpoch.advanced(by: Duration(timeValue)) +#else self = unsafeBitCast(Duration(timeValue), to: SuspendingClock.Instant.self) +#endif } }