diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index c1eb62d..25425ac 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -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: diff --git a/Package.swift b/Package.swift index 263da84..10231c9 100644 --- a/Package.swift +++ b/Package.swift @@ -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"]) ], @@ -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( @@ -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) diff --git a/Sources/WordPressShared/Utility/NSDate+Helpers.swift b/Sources/WordPressShared/Utility/NSDate+Helpers.swift index 4f26d12..7e17260 100644 --- a/Sources/WordPressShared/Utility/NSDate+Helpers.swift +++ b/Sources/WordPressShared/Utility/NSDate+Helpers.swift @@ -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 { diff --git a/Tests/WordPressSharedTests/NSDateHelperTest.swift b/Tests/WordPressSharedTests/NSDateHelperTest.swift index 625bb52..c938168 100644 --- a/Tests/WordPressSharedTests/NSDateHelperTest.swift +++ b/Tests/WordPressSharedTests/NSDateHelperTest.swift @@ -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) } }