DateComponentsFormatter output is incorrect when maximumUnitCount is specified

Number:rdar://FB9944085 Date Originated:Mar 4, 2022 at 10:25 PM
Status:Open Resolved:
Product:Foundation Product Version:
Classification:Incorrect/Unexpected Behavior Reproducible:Yes
When using a DateComponentsFormatter to generate a String, the output will sometimes be "0" when there is a non-zero time difference. It appears to be most common when the time difference is a little less than 1 week.

Tested in Xcode 13.2.1

Please list the steps you took to reproduce the issue:
1. Create a DateComponentsFormatter
2. Set the maximumUnitCount = 1
3. Invoke .string(from: 600000)

let formatter = DateComponentsFormatter()
formatter.maximumUnitCount = 1
let string = formatter.string(from: 600000) ?? ""
print(string) // Outputs "0"

What did you expect to happen?
The output string is "6d"

What actually happened?
The output string is "0"


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at 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!