<!--
{
  "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/input(before:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation4DateV21ComponentsFormatStyleV5input6beforeSnyACGSgAH_tF"
  },
  "title" : "input(before:)"
}
-->

# input(before:)

The next input value before the given input.

```
func input(before input: Range<Date>) -> Range<Date>?
```

## Return Value

If [`isPositive`](/documentation/Foundation/Date/ComponentsFormatStyle/isPositive) is true, the range `input.lowerBound..<x`, where `x` is
the next smaller date that this style can differentiate, or `nil` if there is no such `x` greater or
equal to `input.lowerBound`. If [`isPositive`](/documentation/Foundation/Date/ComponentsFormatStyle/isPositive) is false, the range
`x..<input.upperBound`, where `x` is the next smaller date this style can differentiate.

## Discussion

If [`isPositive`](/documentation/Foundation/Date/ComponentsFormatStyle/isPositive) is true, the next input value maintains the same `lowerBound` as
`input`, but has a different`upperBound`. If [`isPositive`](/documentation/Foundation/Date/ComponentsFormatStyle/isPositive) is false, the next input value
maintains the same `upperBound` as `input`, but as a different `lowerBound`.

Use this function to determine if the return value provided by [`discreteInput(after:)`](/documentation/Foundation/Date/ComponentsFormatStyle/discreteInput(after:)) is
precise enough for your use case for any input `y`:

```
guard let x = style.discreteInput(after: y) else {
    return
}

let z = style.input(before: x) ?? y
```

If the distance between the `upperBound`s of `z` and `x` is too large for the precision you
require, you may want to manually probe `format(_:)` at a higher rate in that interval, as
there is no guarantee for what the output will be in that interval.

---

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)