discreteInput(before:)
The next discretization boundary before the given input.
Declaration
func discreteInput(before input: Range<Date>) -> Range<Date>?Return Value
If isPositve is true, the range input.lowerBound..<x, where x is the greatest date that is smaller than input.upperBound for which this style might produce a different FormatOutput. The function may return nil if there is no such value greater or equal to input.lowerBound. If isPositive is false, the range x..<input.upperBound, where x is the greatest date that is smaller than input.lowerBound for which this style might produce a different FormatOutput.
Discussion
Use this function to determine the next smaller input that warrants updating the formatted output. If isPositive is true, the returned range has the same lowerBound as the input, but reduces the upperBound so that the returned range produces the next smaller output. If isPositive is false, the returned range has the same upperBound as the input and a smaller lowerBound.
let style = Date.ComponentsFormatStyle(style: .wide)
print(style.format(start..<end)) // "1 hour"
guard let next = style.discreteInput(before: start..<end) else {
return
}
print(style.format(next)) // "59 minutes, 59 seconds"