DateComponentsFormatter does not always respect maximumUnitCount
Originator: | siemens.craig | ||
Number: | rdar://44523744 | Date Originated: | 17-Sep-2018 11:02 AM |
Status: | Open | Resolved: | |
Product: | iOS + SDK | Product Version: | 12.0 |
Classification: | Other Bug | Reproducible: | Always |
Summary: DateComponentsFormatter will sometimes show more than the maximumUnitCount when changing DateComponents into a string. Multiple things must be true for the issue to occur: - the first `maximumUnitCount` units must have a non-zero value - the `maximumUnitCount + 1`th unit must have a zero value - the `maximumUnitCount + 2`th unit must have a high enough value to cause the units with 0 to round up to 1 Steps to Reproduce: Run the following in a playground let dateFormatter = DateComponentsFormatter() dateFormatter.unitsStyle = .abbreviated dateFormatter.maximumUnitCount = 1 dateFormatter.string(from: DateComponents(day: 1, hour: 0, minute: 31)) // returns "1d 1h", expected "1d" dateFormatter.maximumUnitCount = 2 dateFormatter.string(from: DateComponents(day: 1, hour: 1, minute: 0, second: 31)) // returns "1d 1h 1m", expected "1d 1h" Expected Results: The first string should be "1d" The second string should be "1d 1h" Actual Results: The first string should be "1d 1h" The second string should be "1d 1h 1m" Version: 12.0 Notes:
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!