Fatal error Foundation/NSCalendar.swift, Ubuntu 16.04, Swift 3.0.1

Hi,

Is this a bug in the NSCalendar.swift? On Ubuntu 16.04 with Swift 3.0.1 installed this crashes.

import Foundation
let fromDate = Date()
let toDate = Date(timeIntervalSinceNow: 20)
let components = Calendar.current.dateComponents([.second], from: fromDate, to: toDate)

Result:

fatal error: file Foundation/NSCalendar.swift, line 615
fromDate: Foundation.Date = {
  _time = <extracting data from value failed>

}
toDate: Foundation.Date = {
  _time = <extracting data from value failed>

}
components: Foundation.DateComponents = {
  _handle = <extracting data from value failed>

}
Execution interrupted. Enter code to recover and continue.
Enter LLDB commands to investigate (type :help for assistance.)

Variations of other components also fails, e.g .hour, .minute etc.

Best regards,
Malcolm

Hi Malcolm,

Looks like it. If you go ahead and file a JIRA at bugs.swift.org <Issues · apple/swift · GitHub, hopefully someone can take a look.

Thanks,
- Tony

···

On Nov 30, 2016, at 6:22 AM, Malcolm Barclay via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

Hi,

Is this a bug in the NSCalendar.swift? On Ubuntu 16.04 with Swift 3.0.1 installed this crashes.

import Foundation
let fromDate = Date()
let toDate = Date(timeIntervalSinceNow: 20)
let components = Calendar.current.dateComponents([.second], from: fromDate, to: toDate)

Result:

fatal error: file Foundation/NSCalendar.swift, line 615
fromDate: Foundation.Date = {
_time = <extracting data from value failed>

}
toDate: Foundation.Date = {
_time = <extracting data from value failed>

}
components: Foundation.DateComponents = {
_handle = <extracting data from value failed>

}
Execution interrupted. Enter code to recover and continue.
Enter LLDB commands to investigate (type :help for assistance.)

Variations of other components also fails, e.g .hour, .minute etc.

Best regards,
Malcolm
_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

Hello Malcolm,

It looks like cutting line 606 of NSCalendar.swift and pasting it over `false` on line 607 fixes the issue.

  1> import Foundation
  2. let fromDate = Date()
  3. let toDate = Date(timeIntervalSinceNow: 20)
  4. let components = Calendar.current.dateComponents([.second], from: fromDate, to: toDate)
// ...
        [6] = 20
// ...

Regards,
Will Stanton

···

On Nov 30, 2016, at 9:22 AM, Malcolm Barclay via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

Hi,

Is this a bug in the NSCalendar.swift? On Ubuntu 16.04 with Swift 3.0.1 installed this crashes.

Hi Will,

Fair enough, I know very little about the inner workings of the Foundation libraries ¯\_(ツ)_/¯ Hoping someone can raise a sensible PR that fixes the issue.

Best regards,
Malcolm

···

On 2 Dec 2016, at 19:58, Will Stanton <willstanton1@yahoo.com> wrote:

Hello Malcolm,

It looks like cutting line 606 of NSCalendar.swift and pasting it over `false` on line 607 fixes the issue.

1> import Foundation
2. let fromDate = Date()
3. let toDate = Date(timeIntervalSinceNow: 20)
4. let components = Calendar.current.dateComponents([.second], from: fromDate, to: toDate)
// ...
       [6] = 20
// ...

Regards,
Will Stanton

On Nov 30, 2016, at 9:22 AM, Malcolm Barclay via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

Hi,

Is this a bug in the NSCalendar.swift? On Ubuntu 16.04 with Swift 3.0.1 installed this crashes.