Skip to content

Commit

Permalink
Rename TZ offset from timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria committed Apr 8, 2024
1 parent 507dccd commit 34947a2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Sources/Confidence/ConfidenceValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 1 addition & 6 deletions Tests/ConfidenceTests/ConfidenceValueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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\",
Expand All @@ -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)
}
}

0 comments on commit 34947a2

Please sign in to comment.