-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Swift 5.8 support, general cleanup
- Loading branch information
Showing
4 changed files
with
122 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// swift-tools-version: 5.7 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
import Foundation | ||
|
||
let package = Package( | ||
name: "simple-formatting", | ||
products: [ | ||
.library(name: "DurationFormatting", | ||
targets: ["DurationFormatting"]), | ||
], | ||
targets: [ | ||
// Targets are the basic building blocks of a package. A target can define a module or a test suite. | ||
// Targets can depend on other targets in this package, and on products in packages this package depends on. | ||
.systemLibrary( | ||
name: "CICUCommon", | ||
pkgConfig: "icu-uc", | ||
providers: [ | ||
.apt(["libicu-dev"]), | ||
.brew(["icu4c"]), | ||
]), | ||
.systemLibrary( | ||
name: "CICUI18N", | ||
pkgConfig: "icu-i18n", | ||
providers: [ | ||
.apt(["libicu-dev"]), | ||
.brew(["icu4c"]), | ||
]), | ||
.systemLibrary( | ||
name: "CICUIO", | ||
pkgConfig: "icu-io", | ||
providers: [ | ||
.apt(["libicu-dev"]), | ||
.brew(["icu4c"]), | ||
]), | ||
.target( | ||
name: "CICUShims", | ||
dependencies: [ | ||
"CICUCommon", | ||
"CICUI18N", | ||
// "CICUIO", | ||
]), | ||
.target( | ||
name: "DurationFormatting", | ||
dependencies: ["CICUShims"]), | ||
.testTarget( | ||
name: "DurationFormattingTests", | ||
dependencies: [ | ||
"CICUShims", | ||
"DurationFormatting", | ||
]), | ||
], | ||
cxxLanguageStandard: .cxx14 | ||
) | ||
|
||
if ProcessInfo.processInfo.environment["ENABLE_DOCC_SUPPORT"] == "1" { | ||
package.dependencies.append(.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Foundation | ||
@_implementationOnly import CICUShims | ||
|
||
fileprivate extension CICUTimeComponent { | ||
func value(droppingZero dropZero: Bool) -> Int? { | ||
isNull || (dropZero && value == .zero) ? nil : numericCast(value) | ||
} | ||
} | ||
|
||
public struct TimeComponents: Hashable, Comparable, Sendable { | ||
public var hour: Int? | ||
public var minute: Int? | ||
public var second: Int? | ||
|
||
@inlinable | ||
public var dateComponents: DateComponents { | ||
.init(hour: hour, minute: minute, second: second) | ||
} | ||
|
||
public init(hour: Int? = nil, | ||
minute: Int? = nil, | ||
second: Int? = nil) { | ||
self.hour = hour | ||
self.minute = minute | ||
self.second = second | ||
} | ||
|
||
@inlinable | ||
public init(dateComponents: DateComponents) { | ||
self.init(hour: dateComponents.hour, | ||
minute: dateComponents.minute, | ||
second: dateComponents.second) | ||
} | ||
|
||
init(_cicuTimeComponents timeComponents: CICUTimeComponents, dropZeros: Bool) { | ||
self.init(hour: timeComponents.hours.value(droppingZero: dropZeros), | ||
minute: timeComponents.minutes.value(droppingZero: dropZeros), | ||
second: timeComponents.seconds.value(droppingZero: dropZeros)) | ||
} | ||
|
||
func _cicuTimeComponents(nullingZeros: Bool) -> CICUTimeComponents { | ||
func _component(for value: Int?) -> CICUTimeComponent { | ||
value.map(numericCast).map(nullingZeros ? CICUTimeComponent.init(nullingZeroOf:) : CICUTimeComponent.init(_:)) ?? .null | ||
} | ||
return .init(hours: _component(for: hour), | ||
minutes: _component(for: minute), | ||
seconds: _component(for: second)) | ||
} | ||
|
||
public static func <(lhs: Self, rhs: Self) -> Bool { | ||
guard lhs != rhs else { return false } | ||
return (lhs.hour ?? 0, lhs.minute ?? 0, lhs.second ?? 0) | ||
< | ||
(rhs.hour ?? 0, rhs.minute ?? 0, rhs.second ?? 0) | ||
} | ||
} |