Is it possible to convince the DateComponentsFormatter that 30 days are also one month as 31 days are?
The backend to which our app is connected to sends a duration of 30 days and this should be displayed as "1 month" duration on the UI.
This is the code I used:
let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.second, .minute, .hour, .day, .weekOfMonth, .month, .year]
formatter.unitsStyle = .full
formatter.maximumUnitCount = 1
formatter.string(from: duration)
And this will be formatted to "4 weeks" when the duration is 30 days and formatted to "1 month" when duration is 31 days.