This is still broken. The following code
import Foundation
let formatter = DateComponentsFormatter()
formatter.unitsStyle = .full
formatter.allowedUnits = [.year, .month, .weekOfMonth, .day, .hour]
formatter.maximumUnitCount = 1
// Use the configured formatter to generate the string.
for i in 0..<30 {
let seconds: TimeInterval = 24.0*3600.0*(Double(i) + 0.5)
print("\(Double(i) + 0.5) days = \(formatter.string(from: seconds)!)")
}
produces the following output. Fractional days seem to really break things.
0.5 days = 12 hours
1.5 days = 2 days
2.5 days = 3 days
3.5 days = 4 days
4.5 days = 5 days
5.5 days = 0 months
6.5 days = 0 months
7.5 days = 1 week
8.5 days = 2 weeks
9.5 days = 2 weeks
10.5 days = 2 weeks
11.5 days = 2 weeks
12.5 days = 2 weeks
13.5 days = 1 week
14.5 days = 2 weeks
15.5 days = 2 weeks
16.5 days = 2 weeks
17.5 days = 2 weeks
18.5 days = 2 weeks
19.5 days = 2 weeks
20.5 days = 2 weeks
21.5 days = 3 weeks
22.5 days = 3 weeks
23.5 days = 3 weeks
24.5 days = 3 weeks
25.5 days = 3 weeks
26.5 days = 3 weeks
27.5 days = 3 weeks
28.5 days = 4 weeks
29.5 days = 4 weeks