The full playground content in case anyone else comes exploring:
import Foundation
//var time1 = Measurement<UnitDuration>(value: 1.23, unit: .seconds)
var time2 = Measurement<UnitDuration>(value: 6.54, unit: .milliseconds)
//var time3 = Measurement<UnitDuration>(value: 9.01, unit: .microseconds)
time2.converted(to: .picoseconds)
let times = [1,10,100,1000,10103,2354,83674,182549].map { Measurement<UnitDuration>(value: $0, unit: .microseconds)
}
//print("\(time1), \(time2), \(time3)")
//print(time1.formatted())
//print(time2.formatted())
//print(time3.formatted())
//for t in times {
// print(t.formatted())
//}
// Static method 'list(type:width:)' requires the types 'Measurement<UnitDuration>' and 'String' be equivalent
// print(times.formatted(.list(type: .and, width: .standard)))
let f = MeasurementFormatter()
print("unitStyle: .short, unitOptions: .naturalScale")
f.unitOptions = .naturalScale
f.unitStyle = .short
for t in times {
print(f.string(from: t))
}
print("unitStyle: .medium, unitOptions: .naturalScale")
f.unitOptions = .naturalScale
f.unitStyle = .medium
for t in times {
print(f.string(from: t))
}
print("unitStyle: .long, unitOptions: .naturalScale")
f.unitOptions = .naturalScale
f.unitStyle = .long
for t in times {
print(f.string(from: t))
}
print("unitStyle: .short, unitOptions: .providedUnit")
f.unitOptions = .providedUnit
f.unitStyle = .short
for t in times {
print(f.string(from: t))
}
print("unitStyle: .medium, unitOptions: .providedUnit")
f.unitOptions = .providedUnit
f.unitStyle = .medium
for t in times {
print(f.string(from: t))
}
print("unitStyle: .long, unitOptions: .providedUnit")
f.unitOptions = .providedUnit
f.unitStyle = .long
for t in times {
print(f.string(from: t))
}