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-3370] Swift 3.0 Migrator badly converts NSCalendar #45958

Closed
swift-ci opened this issue Dec 8, 2016 · 1 comment
Closed

[SR-3370] Swift 3.0 Migrator badly converts NSCalendar #45958

swift-ci opened this issue Dec 8, 2016 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Dec 8, 2016

Previous ID SR-3370
Radar rdar://29574298
Original Reporter stuffmc (JIRA User)
Type Bug
Status Closed
Resolution Invalid
Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 1bb320fa768726862d6c11669742ee93

Issue Description:

This Swift 2.2 code

let calendar = NSCalendar.currentCalendar()

let components = calendar.components([.Day,.Month,.Year], fromDate: pickerDate)
components.timeZone = NSTimeZone(forSecondsFromGMT: 0)
let finalDate = calendar.dateFromComponents(components)!

is changed by the migrator to

let calendar = Calendar.current
        
var components = (calendar as NSCalendar).components([.day,.month,.year], from: pickerDate)
        
(components as NSDateComponents).timeZone = TimeZone(secondsFromGMT: 0)        
let finalDate = calendar.date(from: components)!

The problem is that (components as NSDateComponents).timeZone doesn't change the timeZone of calendar, but of it's copy.

Instead, the migrator should do this

var components = calendar.dateComponents(in: TimeZone.current, from: pickerDate)
components.timeZone = TimeZone(secondsFromGMT: 0)
@akyrtzi
Copy link
Member

akyrtzi commented Dec 9, 2016

Thanks for the report and detailed information!
Since the swift migrator is not part of swift.org we prefer for these to go through https://bugreport.apple.com (which you already filed).
That way you can get notified if a specific Xcode version gets a fix for it.

For reference the associated bug report is rdar://29574298

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

No branches or pull requests

2 participants