Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
apple:
if: github.event_name != 'pull_request' || !contains(github.event.pull_request.title, '[skip ci]')
name: ${{ matrix.platform }} (Swift ${{ matrix.swift }})
runs-on: macos-15
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
Expand All @@ -46,9 +46,13 @@ jobs:
- watchOS
- visionOS
swift:
- "6.0"
- "6.1"
- "6.2"
include:
- swift: "6.1"
runner: macos-15
- swift: "6.2"
runner: macos-26
steps:
- name: Git Checkout
uses: actions/checkout@v5
Expand Down Expand Up @@ -88,7 +92,6 @@ jobs:
fail-fast: false
matrix:
swift:
- "6.0"
- "6.1"
- "6.2"
container:
Expand All @@ -107,7 +110,6 @@ jobs:
fail-fast: false
matrix:
swift:
- "6.0"
- "6.1"
- "6.2"
steps:
Expand All @@ -118,6 +120,4 @@ jobs:
uses: skiptools/swift-android-action@v2
with:
swift-version: ${{ matrix.swift }}
build-tests: ${{ matrix.swift != '6.0' }}
run-tests: ${{ matrix.swift != '6.0' }}
free-disk-space: true
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0
6.1
10 changes: 5 additions & 5 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 15 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// swift-tools-version:6.0
// swift-tools-version: 6.1

import PackageDescription

let package = Package(
name: "Period",
platforms: [
.iOS(.v15),
.macCatalyst(.v15),
.macOS(.v12),
.tvOS(.v15),
.visionOS(.v1),
.watchOS(.v8),
],
products: [
Expand All @@ -21,20 +23,28 @@ let package = Package(
"Period",
.product(name: "JSONTesting", package: "swift-json-testing"),
],
path: "Tests"
path: "Tests",
),

.executableTarget(
name: "Benchmarks",
dependencies: [
"Period",
.product(name: "Benchmark", package: "swift-benchmark"),
]
],
),
]
],
)

package.dependencies = [
package.dependencies += [
.package(url: "https://github.com/google/swift-benchmark", from: "0.1.2"),
.package(url: "https://github.com/davdroman/swift-json-testing", from: "0.2.0"),
]

for target in package.targets {
target.swiftSettings = target.swiftSettings ?? []
target.swiftSettings? += [
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("InternalImportsByDefault"),
]
}
8 changes: 4 additions & 4 deletions Sources/Period/Arithmetic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension Period {
days: -rhs.days,
hours: -rhs.hours,
minutes: -rhs.minutes,
seconds: -rhs.seconds
seconds: -rhs.seconds,
)
}

Expand All @@ -25,7 +25,7 @@ extension Period {
days: lhs.days + rhs.days,
hours: lhs.hours + rhs.hours,
minutes: lhs.minutes + rhs.minutes,
seconds: lhs.seconds + rhs.seconds
seconds: lhs.seconds + rhs.seconds,
)
}

Expand All @@ -42,7 +42,7 @@ extension Period {
days: lhs.days - rhs.days,
hours: lhs.hours - rhs.hours,
minutes: lhs.minutes - rhs.minutes,
seconds: lhs.seconds - rhs.seconds
seconds: lhs.seconds - rhs.seconds,
)
}

Expand All @@ -59,7 +59,7 @@ extension Period {
days: lhs.days * rhs,
hours: lhs.hours * rhs,
minutes: lhs.minutes * rhs,
seconds: lhs.seconds * rhs
seconds: lhs.seconds * rhs,
)
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/Period/Calendar.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Foundation
public import Foundation

extension Calendar {
public func date(byAdding period: Period, to date: Date, wrappingComponents: Bool = false) -> Date? {
Expand All @@ -13,7 +13,7 @@ extension Calendar {
days: components.day ?? 0,
hours: components.hour ?? 0,
minutes: components.minute ?? 0,
seconds: components.second ?? 0
seconds: components.second ?? 0,
)
}
}
Expand All @@ -26,7 +26,7 @@ extension DateComponents {
day: period.days,
hour: period.hours,
minute: period.minutes,
second: period.seconds
second: period.seconds,
)
}
}
6 changes: 3 additions & 3 deletions Sources/Period/Codable.swift
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import Foundation

extension Period: Codable {
public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let rawValue = try container.decode(String.self)
do {
self = try Period(rawValue, format: .iso8601)
} catch {
throw DecodingError.dataCorruptedError(
in: container,
debugDescription: "Invalid ISO 8601 duration \"\(rawValue)\""
debugDescription: "Invalid ISO 8601 duration \"\(rawValue)\"",
)
}
}

public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(self.formatted(.iso8601))
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Period/Formatting.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#if canImport(Darwin)
import Foundation
public import Foundation

extension Period {
public struct FormatStyle: Foundation.FormatStyle, Sendable {
Expand Down
6 changes: 3 additions & 3 deletions Sources/Period/ISO8601.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Foundation
public import Foundation

extension Period {
public struct ISO8601FormatStyle: ParseableFormatStyle, ParseStrategy {
Expand Down Expand Up @@ -41,7 +41,7 @@ extension Period {

enum Parser {
static let regex = try! NSRegularExpression(
pattern: #"([+-])?P(?:(-?\d+)?Y)?(?:(-?\d+)?M)?(?:(-?\d+)?W)?(?:(-?\d+)?D)?(?:T(?:(-?\d+)?H)?(?:(-?\d+)?M)?(?:(-?\d+)?S)?)?"#
pattern: #"([+-])?P(?:(-?\d+)?Y)?(?:(-?\d+)?M)?(?:(-?\d+)?W)?(?:(-?\d+)?D)?(?:T(?:(-?\d+)?H)?(?:(-?\d+)?M)?(?:(-?\d+)?S)?)?"#,
)

static func parse(_ string: String) -> Period? {
Expand Down Expand Up @@ -94,7 +94,7 @@ extension Period {
days: ((weeks ?? 0) * 7 + (days ?? 0)) * leadingSign,
hours: (hours ?? 0) * leadingSign,
minutes: (minutes ?? 0) * leadingSign,
seconds: (seconds ?? 0) * leadingSign
seconds: (seconds ?? 0) * leadingSign,
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Period/Period.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public struct Period: Hashable, Sendable {
days: Int = 0,
hours: Int = 0,
minutes: Int = 0,
seconds: Int = 0
seconds: Int = 0,
) {
self.years = years
self.months = months
Expand Down
6 changes: 3 additions & 3 deletions Tests/DescriptionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ struct DescriptionTests {
@Test func periodDescription() {
#expect(
Period.zero.description
== ""
== "",
)
#expect(
Period(years: 1, months: 1, days: 1, hours: 1, minutes: 1, seconds: 1).description
== "1 year, 1 month, 1 day, 1 hour, 1 minute, 1 second"
== "1 year, 1 month, 1 day, 1 hour, 1 minute, 1 second",
)
#expect(
Period(years: 3, months: 3, days: 3, hours: 3, minutes: 3, seconds: 3).description
== "3 years, 3 months, 3 days, 3 hours, 3 minutes, 3 seconds"
== "3 years, 3 months, 3 days, 3 hours, 3 minutes, 3 seconds",
)
}
}
16 changes: 8 additions & 8 deletions Tests/FormattingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ extension FormattingTests {
@Test func periodFormatting_defaultStyle() {
#expect(
Period.zero.formatted(.full.locale(enLocale))
== "0 seconds"
== "0 seconds",
)
#expect(
Period(years: 1, months: 2, days: 3, hours: 4, minutes: 5, seconds: 6).formatted(.full.locale(enLocale))
== "1 year, 2 months, 3 days, 4 hours, 5 minutes, 6 seconds"
== "1 year, 2 months, 3 days, 4 hours, 5 minutes, 6 seconds",
)
}
}
Expand All @@ -25,11 +25,11 @@ extension FormattingTests {
@Test func periodFormatting_explicitStyle() {
#expect(
Period.zero.formatted(.short.locale(enLocale))
== "0 secs"
== "0 secs",
)
#expect(
Period(years: 1, months: 2, days: 3, hours: 4, minutes: 5, seconds: 6).formatted(.short.locale(enLocale))
== "1 yr, 2 mths, 3 days, 4 hrs, 5 min, 6 secs"
== "1 yr, 2 mths, 3 days, 4 hrs, 5 min, 6 secs",
)
}
}
Expand All @@ -38,11 +38,11 @@ extension FormattingTests {
@Test func periodFormatting_customAllowedUnits() {
#expect(
Period.zero.formatted(.full.allowedUnits([.day, .hour, .minute, .second]).locale(enLocale))
== "0 seconds"
== "0 seconds",
)
#expect(
Period(years: 1, months: 2, days: 3, hours: 4, minutes: 5, seconds: 6).formatted(.full.allowedUnits([.day, .hour, .minute, .second]).locale(enLocale))
== "427 days, 4 hours, 5 minutes, 6 seconds"
== "427 days, 4 hours, 5 minutes, 6 seconds",
)
}
}
Expand All @@ -51,11 +51,11 @@ extension FormattingTests {
@Test func periodFormatting_esLocale() {
#expect(
Period.zero.formatted(.full.locale(esLocale))
== "0 segundos"
== "0 segundos",
)
#expect(
Period(years: 1, months: 2, days: 3, hours: 4, minutes: 5, seconds: 6).formatted(.full.locale(esLocale))
== "1 año, 2 meses, 3 días, 4 horas, 5 minutos y 6 segundos"
== "1 año, 2 meses, 3 días, 4 horas, 5 minutos y 6 segundos",
)
}
}
Expand Down
Loading