Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Swift 5.10 toolchain #355

Merged
merged 3 commits into from
Apr 16, 2024
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
2 changes: 1 addition & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ common_params:
plugins: &common_plugins
- automattic/a8c-ci-toolkit#3.1.0
env: &common_env
IMAGE_ID: xcode-15.0.1
IMAGE_ID: xcode-15.3-v3

# This is the default pipeline – it will build and test the pod
steps:
Expand Down
14 changes: 8 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// swift-tools-version:5.5
// swift-tools-version:5.10

import Foundation
import PackageDescription

let package = Package(
name: "WordPressShared",
platforms: [.iOS(.v13)],
platforms: [.iOS(.v13), .macOS(.v12)],
products: [
.library(name: "WordPressShared", targets: ["WordPressShared"])
],
Expand All @@ -15,7 +15,7 @@ let package = Package(
// See https://github.com/erikdoe/ocmock/issues/500#issuecomment-1002700625
.package(url: "https://github.com/erikdoe/ocmock", revision: "afd2c6924e8a36cb872bc475248b978f743c6050"),
.package(url: "https://github.com/Quick/Quick", from: "6.0.0"),
.package(url: "https://github.com/realm/SwiftLint", .exactItem(loadSwiftLintVersion()))
.package(url: "https://github.com/realm/SwiftLint", exact: loadSwiftLintVersion())
],
targets: [
.target(
Expand Down Expand Up @@ -63,10 +63,12 @@ let package = Package(
)

func loadSwiftLintVersion() -> Version {
guard let yamlString = try? String(contentsOf: URL(fileURLWithPath: #file)
let swiftLintConfigURL = URL(fileURLWithPath: #file)
.deletingLastPathComponent()
.appendingPathComponent(".swiftlint.yml")) else {
fatalError("Failed to read YAML file.")
.appendingPathComponent(".swiftlint.yml")

guard let yamlString = try? String(contentsOf: swiftLintConfigURL) else {
fatalError("Failed to read SwiftLint config file at \(swiftLintConfigURL).")
}

guard let versionLine = yamlString.components(separatedBy: .newlines)
Expand Down
9 changes: 2 additions & 7 deletions Sources/WordPressShared/Utility/NSDate+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,9 @@ extension Date {
}

/// Formats the current date as a medium relative date/time.
/// - Parameter timeZone: An optional time zone used to adjust the date formatters.
///
/// - Example: Tomorrow, 6:45 AM
/// - Example: Today, 8:09 AM
/// - Example: Yesterday, 11:36 PM
/// - Example: Jan 28, 2017, 1:51 PM
/// - Example: Jan 22, 2017, 2:18 AM
/// That is, it uses the `DateFormatter` `dateStyle` `.medium` and `timeStyle` `.short`.
///
/// - Parameter timeZone: An optional time zone used to adjust the date formatters.
public func mediumStringWithTime(timeZone: TimeZone? = nil) -> String {
let formatter = DateFormatters.mediumDateTime
if let timeZone = timeZone {
Expand Down
12 changes: 8 additions & 4 deletions Tests/WordPressSharedTests/NSDateHelperTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,26 @@ class NSDateHelperTest: XCTestCase {
}

/// Verifies that `mediumStringWithTime` takes into account the time zone adjustment
/// If this test is failing, check that the Test Plan is still using en-US as its language
///
/// This legacy test is a bit silly because it is simply testing that the code calls `DateFormatter` with the expected configuration.
/// This was done to make the test robust against underlying changes in `DateFormatter`'s behavior.
/// Example failure this avoids: https://buildkite.com/automattic/wordpress-shared-ios/builds/235#018ed45e-c2be-40e5-9759-6bd7c0735ce9/6-2623
func testMediumStringTimeZoneAdjust() {
let date = Date()
let timeZone = TimeZone(secondsFromGMT: Calendar.current.timeZone.secondsFromGMT() - (60 * 60))
XCTAssertEqual(date.toMediumString(inTimeZone: timeZone), "now")

let timeFormatter = DateFormatter()
timeFormatter.dateStyle = .none
timeFormatter.doesRelativeDateFormatting = true
timeFormatter.dateStyle = .medium
timeFormatter.timeStyle = .short
let withoutTimeZoneAdjust = timeFormatter.string(from: date)

XCTAssertEqual(date.mediumStringWithTime(), "Today, \(withoutTimeZoneAdjust)")
XCTAssertEqual(date.mediumStringWithTime(), withoutTimeZoneAdjust)

timeFormatter.timeZone = timeZone
let withTimeZoneAdjust = timeFormatter.string(from: date)

XCTAssertEqual(date.mediumStringWithTime(timeZone: timeZone), "Today, \(withTimeZoneAdjust)")
XCTAssertEqual(date.mediumStringWithTime(timeZone: timeZone), withTimeZoneAdjust)
}
}