Details
-
Type:
Bug
-
Status: Closed
-
Priority:
Medium
-
Resolution: Invalid
-
Component/s: None
-
Labels:None
-
Radar URL:
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)