Skip to content
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
7 changes: 7 additions & 0 deletions Sources/Foundation/ISO8601DateFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ open class ISO8601DateFormatter : Formatter, NSSecureCoding {
aCoder.encode(timeZone._nsObject, forKey: "NS.timeZone")
}
}

open override func copy(with zone: NSZone? = nil) -> Any {
let copied = ISO8601DateFormatter()
copied.timeZone = timeZone
copied.formatOptions = formatOptions
return copied
}

public static var supportsSecureCoding: Bool { return true }

Expand Down
23 changes: 23 additions & 0 deletions Tests/Foundation/Tests/TestISO8601DateFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,28 @@ class TestISO8601DateFormatter: XCTestCase {
try fixture.assertLoadedValuesMatch(areEqual(_:_:))
}
}

func test_copy() throws {
let original = ISO8601DateFormatter()
original.timeZone = try XCTUnwrap(TimeZone(identifier: "GMT"))
original.formatOptions = [
.withInternetDateTime,
.withDashSeparatorInDate,
.withColonSeparatorInTime,
.withColonSeparatorInTimeZone,
]

let copied = try XCTUnwrap(original.copy() as? ISO8601DateFormatter)
XCTAssertEqual(copied.timeZone, original.timeZone)
XCTAssertEqual(copied.formatOptions, original.formatOptions)

copied.timeZone = try XCTUnwrap(TimeZone(identifier: "JST"))
copied.formatOptions.insert(.withFractionalSeconds)
XCTAssertNotEqual(copied.timeZone, original.timeZone)
XCTAssertNotEqual(copied.formatOptions, original.formatOptions)
XCTAssertFalse(original.formatOptions.contains(.withFractionalSeconds))
XCTAssertTrue(copied.formatOptions.contains(.withFractionalSeconds))
}

static var allTests : [(String, (TestISO8601DateFormatter) -> () throws -> Void)] {

Expand All @@ -335,6 +357,7 @@ class TestISO8601DateFormatter: XCTestCase {
("test_stringFromDateClass", test_stringFromDateClass),
("test_codingRoundtrip", test_codingRoundtrip),
("test_loadingFixtures", test_loadingFixtures),
("test_copy", test_copy),
]
}
}