I would like to format TimeInterval values, but DateComponentsFormatter doesn't seem to respect `allowsFractionalUnits`.
let formatter = DateComponentsFormatter()
formatter.unitsStyle = .full
formatter.allowedUnits = [.hour]
formatter.allowsFractionalUnits = true
let durations:[TimeInterval] = [1800.0, 3600.0, 5400.0, 7200.0, 10000.0]
durations.forEach{ print("\($0) -> \(formatter.string(from: $0)!)") }
This code produces the following output:
1800.0 -> 0 hours
3600.0 -> 1 hour
5400.0 -> 1 hour
7200.0 -> 2 hours
10000.0 -> 2 hours
I was expecting it to print something like:
1800.0 -> 0.5 hours
3600.0 -> 1 hour
5400.0 -> 1.5 hours
7200.0 -> 2 hours
10000.0 -> 2.8 hours
Am I doing something wrong?