Skip to content

[SR-14108] DateFormatter is not copied by copy() with SwiftFoundation. #3235

@YOCKOW

Description

@YOCKOW
Previous ID SR-14108
Radar rdar://problem/73742491
Original Reporter @YOCKOW
Type Sub-task
Status Resolved
Resolution Done
Environment

Swift 5.3.2
Ubuntu 20.04

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Sub-task
Assignee @YOCKOW
Priority Medium

md5: 18c43438b829dd3084a420779b428634

Parent-Task:

  • SR-14908 Implement func copy() in subclasses of Formatter.

Issue Description:

DateFormatter.copy() returns the same instance not a copied one as you can see with following code:

import Foundation

let formatter: DateFormatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"

print(formatter.string(from: Date()))
// Prints "2021-01-26"

let copiedFormatter = formatter.copy() as! DateFormatter
copiedFormatter.dateFormat = "yyyy/MM/dd"

print(formatter.string(from: Date()))
// Prints "2021-01-26" on Darwin
// Prints "2021/01/26" on non-Darwin

print(copiedFormatter.string(from: Date()))
// Prints "2021/01/26"

It may be caused by https://github.com/apple/swift-corelibs-foundation/blob/f17b5a25bbc604126a8c6aca8b0b75c2e0291a6c/Sources/Foundation/Formatter.swift#L60-L66

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions