Calendar Component Quarter always returns zero

I'm doing some summarising of dated data from Coredata using @SectionedFetchRequest and SwiftUI List with Section headers. Summary options are by week, month, quarter and year, with processing by Calendar Component. All works fine (with a bit of extra processing for the week period description) except for quarter, which always returns zero instead of 1 to 4. When I finally decided to look at the documentation https://developer.apple.com/documentation/foundation/calendar/component/quarter there's an Important note saying "The quarter unit is largely unimplemented, and is not recommended for use.". So why have that enumeration if it's known not to work?

OK, so I now get the month and then determine the quarter with a switch statement.......

You answered in fact to your own question.

You could however file a bug report to ask for enhancement.

Right now it’s wasting developers’ time.

Agreed. We have a bug to track fixing NSCalendar (r. 30033548) but IMO you should file a bug to get the constant deprecated until such time as it’s been fixed.

Please post your bug number, just for the record.

so I now get the month and then determine the quarter with a switch statement

If you do this, make sure you hard wire your calendar to .gregorian. The concept of calendar quarter can be made to work in other calendars but it’s not as simple as a switch statement (for example, when the calendar has leap months).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Calendar Component Quarter always returns zero
 
 
Q