Uploaded image for project: 'Swift'
  1. Swift
  2. SR-3370

Swift 3.0 Migrator badly converts NSCalendar

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Medium
    • Resolution: Invalid
    • Component/s: None
    • Labels:
      None

      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)
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              stuffmc Manuel "StuFF mc" Carrasco Molina
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: