From 9cab6bbb3511c2672fddbe09f483795ab77ccd3f Mon Sep 17 00:00:00 2001 From: Fabrizio Demaria Date: Tue, 5 Nov 2024 13:33:08 +0100 Subject: [PATCH] test: date formatter in tests iOS18 (#168) Release-As: 1.0.0 --- Tests/ConfidenceProviderTests/ConfidenceTypeMapperTest.swift | 2 ++ Tests/ConfidenceTests/ConfidenceIntegrationTest.swift | 1 + Tests/ConfidenceTests/ConfidenceValueTests.swift | 3 +++ Tests/ConfidenceTests/TypeMapperTests.swift | 1 + 4 files changed, 7 insertions(+) diff --git a/Tests/ConfidenceProviderTests/ConfidenceTypeMapperTest.swift b/Tests/ConfidenceProviderTests/ConfidenceTypeMapperTest.swift index 35988d71..3964cff7 100644 --- a/Tests/ConfidenceProviderTests/ConfidenceTypeMapperTest.swift +++ b/Tests/ConfidenceProviderTests/ConfidenceTypeMapperTest.swift @@ -64,6 +64,7 @@ class ValueConverterTest: XCTestCase { func testContextConversionWithLists() throws { let formatter = DateFormatter() + formatter.locale = Locale(identifier: "en_US_POSIX") formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" let date1 = try XCTUnwrap(formatter.date(from: "2022-01-01 12:00:00")) let date2 = try XCTUnwrap(formatter.date(from: "2022-01-02 12:00:00")) @@ -112,6 +113,7 @@ class ValueConverterTest: XCTestCase { func testValueConversion() throws { let formatter = DateFormatter() + formatter.locale = Locale(identifier: "en_US_POSIX") formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" let date = try XCTUnwrap(formatter.date(from: "2022-01-01 12:00:00")) diff --git a/Tests/ConfidenceTests/ConfidenceIntegrationTest.swift b/Tests/ConfidenceTests/ConfidenceIntegrationTest.swift index 32732c10..c3f2c096 100644 --- a/Tests/ConfidenceTests/ConfidenceIntegrationTest.swift +++ b/Tests/ConfidenceTests/ConfidenceIntegrationTest.swift @@ -178,6 +178,7 @@ class ConfidenceIntegrationTests: XCTestCase { private func convertStringToDate(_ dateString: String) -> Date? { let dateFormatter = DateFormatter() + dateFormatter.locale = Locale(identifier: "en_US_POSIX") dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ" return dateFormatter.date(from: dateString) } diff --git a/Tests/ConfidenceTests/ConfidenceValueTests.swift b/Tests/ConfidenceTests/ConfidenceValueTests.swift index 902f50a2..37c8535c 100644 --- a/Tests/ConfidenceTests/ConfidenceValueTests.swift +++ b/Tests/ConfidenceTests/ConfidenceValueTests.swift @@ -29,6 +29,7 @@ final class ConfidenceConfidenceValueTests: XCTestCase { func testStringShouldConvertToDate() throws { let formatter = DateFormatter() + formatter.locale = Locale(identifier: "en_US_POSIX") formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" let date = try XCTUnwrap(formatter.date(from: "2022-01-01 12:00:00")) let value = ConfidenceValue(timestamp: date) @@ -43,6 +44,7 @@ final class ConfidenceConfidenceValueTests: XCTestCase { func testListShouldConvertToList() throws { let formatter = DateFormatter() + formatter.locale = Locale(identifier: "en_US_POSIX") formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" formatter.timeZone = TimeZone(abbreviation: "UTC") let date1 = try XCTUnwrap(formatter.date(from: "2022-01-01 12:00:00")) @@ -106,6 +108,7 @@ final class ConfidenceConfidenceValueTests: XCTestCase { func testEncodeDecode() throws { let formatter = DateFormatter() + formatter.locale = Locale(identifier: "en_US_POSIX") formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" formatter.timeZone = TimeZone(abbreviation: "EDT") // Verify TimeZone conversion let date = try XCTUnwrap(formatter.date(from: "2024-04-05 16:00:00")) diff --git a/Tests/ConfidenceTests/TypeMapperTests.swift b/Tests/ConfidenceTests/TypeMapperTests.swift index ac5168f7..88c50f3a 100644 --- a/Tests/ConfidenceTests/TypeMapperTests.swift +++ b/Tests/ConfidenceTests/TypeMapperTests.swift @@ -38,6 +38,7 @@ class TypeMapperTests: XCTestCase { func testConfidenceToNetwork() throws { let formatter = DateFormatter() + formatter.locale = Locale(identifier: "en_US_POSIX") formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" formatter.timeZone = TimeZone.init(identifier: "UTC+01") let date = try XCTUnwrap(formatter.date(from: "2022-01-01 12:00:00"))