<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/Date/ComponentsFormatStyle/discreteInput(before:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation4DateV21ComponentsFormatStyleV13discreteInput6beforeSnyACGSgAH_tF"
  },
  "title" : "discreteInput(before:)"
}
-->

# discreteInput(before:)

The next discretization boundary before the given input.

```
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`](/documentation/Foundation/FormatStyle/FormatOutput). The function may return `nil` if there is no such
value greater or equal to `input.lowerBound`. If [`isPositive`](/documentation/Foundation/Date/ComponentsFormatStyle/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`](/documentation/Foundation/FormatStyle/FormatOutput).

## Discussion

Use this function to determine the next smaller input that warrants updating the formatted output.
If [`isPositive`](/documentation/Foundation/Date/ComponentsFormatStyle/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`](/documentation/Foundation/Date/ComponentsFormatStyle/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"
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)