Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
YOCKOW opened this issue Jan 26, 2021 · 6 comments
Closed

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

YOCKOW opened this issue Jan 26, 2021 · 6 comments
Assignees

Comments

@YOCKOW
Copy link
Collaborator

YOCKOW commented Jan 26, 2021

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

open override func copy() -> Any {
return copy(with: nil)
}
open func copy(with zone: NSZone? = nil) -> Any {
return self
}

@typesanitizer
Copy link

@swift-ci create

@spevans
Copy link
Collaborator

spevans commented Feb 3, 2021

Each subclass of Formatter needs to implement its own override of this method.

@YOCKOW
Copy link
Collaborator Author

YOCKOW commented Jul 13, 2021

Update this issue as a sub-task of SR-14908

@YOCKOW
Copy link
Collaborator Author

YOCKOW commented Jul 14, 2021

#3008

@YOCKOW
Copy link
Collaborator Author

YOCKOW commented Jul 18, 2021

@YOCKOW
Copy link
Collaborator Author

YOCKOW commented Jul 19, 2021

main: 0e4e031
5.5: 2d714e6
5.4: 8c439c5

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants