Calendar.enumerateDates internal infinite loop

Originator:sr
Number:rdar://34011674 Date Originated:August 22 2017
Status:open Resolved:
Product:Foundation Product Version:iOS 11
Classification:Bug Reproducible:always
 
Area:
Foundation

Summary:
Calling Calendar.enumerateDates(startingAfter:, matching:, matchingPolicy:, using:) with certain start dates will hang execution with what looks like an internal infinite loop at year boundaries.

Steps to Reproduce:
Call the mentioned API with certain parameters, see attached playground.

import Foundation

let cal = Calendar(identifier: .gregorian)
let comps = DateComponents(day: 1)
let startDate = ISO8601DateFormatter().date(from: "2017-08-20T00:00:00Z")!

cal.enumerateDates(startingAfter: startDate, matching: comps, matchingPolicy: .nextTime) { (date, _, _) in
    print(date!)
}

Expected Results:
print out of every start of the month after the start date

Observed Results:
four values being printed, then the program execution hangs

2017-08-31 22:00:00 +0000
2017-09-30 22:00:00 +0000
2017-10-31 23:00:00 +0000
2017-11-30 23:00:00 +0000

my local timezone being Europe/Berlin (which does not seem to influence the results, though)

Version:
iOS 11 beta from Xcode Version 9.0 beta 6 (9M214v) 
also seen live on device with iOS 11 beta 7

Attachment: Playground with same code as above

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!