From 34947a2ca52a370fce04a61b2c82615b8fe0c49f Mon Sep 17 00:00:00 2001 From: Fabrizio Demaria Date: Mon, 8 Apr 2024 17:33:08 +0200 Subject: [PATCH] Rename TZ offset from timestamps --- Sources/Confidence/ConfidenceValue.swift | 2 +- Tests/ConfidenceTests/ConfidenceValueTests.swift | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Sources/Confidence/ConfidenceValue.swift b/Sources/Confidence/ConfidenceValue.swift index 63f147be..faa6a45f 100644 --- a/Sources/Confidence/ConfidenceValue.swift +++ b/Sources/Confidence/ConfidenceValue.swift @@ -260,7 +260,7 @@ extension ConfidenceValueInternal { } case .timestamp(let date): let timestampFormatter = ISO8601DateFormatter() - timestampFormatter.timeZone = TimeZone.current + timestampFormatter.timeZone = TimeZone.init(identifier: "UTC") let timestamp = timestampFormatter.string(from: date) try container.encode(timestamp) case .structure(let structure): diff --git a/Tests/ConfidenceTests/ConfidenceValueTests.swift b/Tests/ConfidenceTests/ConfidenceValueTests.swift index 1a312c94..08617c7d 100644 --- a/Tests/ConfidenceTests/ConfidenceValueTests.swift +++ b/Tests/ConfidenceTests/ConfidenceValueTests.swift @@ -126,9 +126,6 @@ final class ConfidenceConfidenceValueTests: XCTestCase { encoder.outputFormatting = .sortedKeys let resultString = String(data: try encoder.encode(value), encoding: .utf8) - let isoFormatter = ISO8601DateFormatter() - isoFormatter.timeZone = TimeZone.current - let expectedSerializedTimestamp = isoFormatter.string(from: date) let expectedString = """ {\"bool\":true, \"date\":\"2024-04-03\", @@ -138,11 +135,9 @@ final class ConfidenceConfidenceValueTests: XCTestCase { \"null\":null, \"string\":\"value\", \"structure\":{\"int\":5}, - \"timestamp\":\"\(expectedSerializedTimestamp)\"} + \"timestamp\":\"2024-04-05T20:00:00Z"} """.replacingOccurrences(of: "\n", with: "") // Newlines were added for readability - // The "base" timestamp is in UTC, but the local offset is added (e.g. "+002"). - XCTAssertTrue(expectedSerializedTimestamp.starts(with: "2024-04-05T22:00:00")) XCTAssertEqual(resultString, expectedString) } }