diff --git a/.github/workflows/VerifyChanges.yaml b/.github/workflows/VerifyChanges.yaml index 2baaa5c..d9a7d72 100644 --- a/.github/workflows/VerifyChanges.yaml +++ b/.github/workflows/VerifyChanges.yaml @@ -6,6 +6,9 @@ on: push: branches: ["main"] +env: + XCODE_VERSION: 26.0.1 + jobs: lint: name: Lint @@ -13,9 +16,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Select Xcode 26.0.0 - run: | - sudo xcode-select -s /Applications/Xcode_26.0.0.app + - name: Select Xcode ${{ env.XCODE_VERSION }} + run: sudo xcode-select -s /Applications/Xcode_${{ env.XCODE_VERSION }}.app - name: Lint run: | Scripts/lint @@ -55,8 +57,8 @@ jobs: XCODE_TEST_PRODUCTS_PATH: .build/DevFoundation.xctestproducts steps: - - name: Select Xcode 26.0.0 - run: sudo xcode-select -s /Applications/Xcode_26.0.0.app + - name: Select Xcode ${{ env.XCODE_VERSION }} + run: sudo xcode-select -s /Applications/Xcode_${{ env.XCODE_VERSION }}.app - name: Checkout uses: actions/checkout@v4 @@ -73,12 +75,12 @@ jobs: uses: actions/cache/restore@v4 with: path: ${{ env.XCODE_TEST_PRODUCTS_PATH }} - key: cache-xctestproducts-${{ github.workflow }}-${{ matrix.platform }}-${{ github.sha }} + key: cache-xctestproducts-${{ github.workflow }}-${{ matrix.platform }}-${{ env.XCODE_VERSION }}-${{ github.sha }} - uses: irgaly/xcode-cache@v1 if: steps.cache-xctestproducts-restore.outputs.cache-hit != 'true' with: - key: xcode-cache-deriveddata-${{ github.workflow }}-${{ matrix.platform }}-${{ github.sha }} + key: xcode-cache-deriveddata-${{ github.workflow }}-${{ matrix.platform }}-${{ env.XCODE_VERSION }}-${{ github.sha }} restore-keys: | xcode-cache-deriveddata-${{ github.workflow }}-${{ matrix.platform }}- xcode-cache-deriveddata- diff --git a/CHANGELOG.md b/CHANGELOG.md index aa7b01b..5da5404 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ # DevFoundation Changelog -## 1.3.0: TBD +## 1.3.0: October 8, 2025 + - We’ve added a computed property spelled `timeInterval` to `Duration`, which returns the + duration as a `TimeInterval`. - We’ve updated the internal implementation of `ContextualEventBusObserver` to use an actor instead of a class with a dispatch queue. This should have no impact on consumers. diff --git a/Sources/DevFoundation/Extensions/Duration+TimeInterval.swift b/Sources/DevFoundation/Extensions/Duration+TimeInterval.swift new file mode 100644 index 0000000..7655d97 --- /dev/null +++ b/Sources/DevFoundation/Extensions/Duration+TimeInterval.swift @@ -0,0 +1,18 @@ +// +// Duration+TimeInterval.swift +// DevFoundation +// +// Created by Prachi Gauriar on 10/8/25. +// + +import Foundation + +extension Duration { + /// A `TimeInterval` representation of the duration. + /// + /// This computed property converts the duration to a `TimeInterval` by dividing the duration by one second. This is + /// useful for interoperability with APIs that expect `TimeInterval` values, such as Foundation’s `Date` APIs. + public var timeInterval: TimeInterval { + TimeInterval(self / .seconds(1.0)) + } +} diff --git a/Tests/DevFoundationTests/Extensions/Duration+TimeIntervalTests.swift b/Tests/DevFoundationTests/Extensions/Duration+TimeIntervalTests.swift new file mode 100644 index 0000000..120f16d --- /dev/null +++ b/Tests/DevFoundationTests/Extensions/Duration+TimeIntervalTests.swift @@ -0,0 +1,33 @@ +// +// Duration+TimeIntervalTests.swift +// DevFoundation +// +// Created by Prachi Gauriar on 10/8/25. +// + +import DevFoundation +import DevTesting +import Foundation +import RealModule +import Testing + +struct Duration_TimeIntervalTests: RandomValueGenerating { + var randomNumberGenerator = makeRandomNumberGenerator() + + + @Test + mutating func timeIntervalReturnsCorrectValue() { + #expect(Duration.seconds(0).timeInterval == 0) + #expect(Duration.milliseconds(-500).timeInterval == -0.5) + #expect(Duration.milliseconds(1375).timeInterval == 1.375) + + for _ in 0 ..< 100 { + let originalTimeInterval = random(TimeInterval.self, in: -100_000 ... 100_000) + #expect( + Duration + .seconds(originalTimeInterval).timeInterval + .isApproximatelyEqual(to: originalTimeInterval, absoluteTolerance: 0.001) + ) + } + } +}