Calendar.enumerateDates misses matching dates
| Originator: | maciektr | ||
| Number: | rdar://34205701 | Date Originated: | September 1 2017 |
| Status: | open | Resolved: | |
| Product: | Foundation | Product Version: | iOS 11 |
| Classification: | Bug | Reproducible: | Always |
Area:
Foundation
Summary:
In certain setups (see example) Calendar.enumerateDates produces unexpected results that differ from the iOS 10 implementation.
Steps to Reproduce:
Run the following code
import Foundation
let date = Date(timeIntervalSinceReferenceDate: 525913200)
let calendar = Calendar.current
let components = calendar.dateComponents([.month, .hour], from: date)
var dates = [Date]()
var count = 0
calendar.enumerateDates(startingAfter: date, matching: components, matchingPolicy: .strict) { (date, exact, stop) in
print(date ?? "nil")
count += 1
stop = count > 5
}
Expected Results:
Print dates incremented by day (that's what happens in iOS 10):
2017-09-01 23:00:00 +0000
2017-09-02 23:00:00 +0000
2017-09-03 23:00:00 +0000
2017-09-04 23:00:00 +0000
2017-09-05 23:00:00 +0000
2017-09-06 23:00:00 +0000
Actual Results:
Dates are incremented by year:
2018-08-31 23:00:00 +0000
2019-08-31 23:00:00 +0000
2020-08-31 23:00:00 +0000
2021-08-31 23:00:00 +0000
2022-08-31 23:00:00 +0000
2023-08-31 23:00:00 +0000
Version/Build:
iOS 11 beta from Xcode Version 9.0 beta 6 (9M214v)
Also seen in the attached playground.
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!