Hi!
When using string method of DateComponentsFormatter, it gives sometimes an extra unit(2) in the formatted string instead of one.
In the following snippet, formattedString gives 213d 1h instead of 213d.
let durationShort: DateComponentsFormatter = {
let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.day, .hour, .minute]
formatter.unitsStyle = .abbreviated
formatter.zeroFormattingBehavior = .dropAll
formatter.maximumUnitCount = 3
formatter.collapsesLargestUnit = false
return formatter
}()
let formattedString = durationShort.string(from: TimeInterval(86400 * 213))
Any idea?
7
0
2.6k