A style for formatting a date interval in terms of specific date components.
Members (18)
get · iOS 18.0+
isPositive
TypeScript
get isPositive(): boolean
Swift declaration
var isPositive: Bool
Controls whether the format input is formatted as a positive or negative range.
When the range is formatted as a positive value, the returned string describes the time
from `lowerBound` to `upperBound`. When `isPositive` is set to `false`, the
returned string describes the time from `upperBound` to `lowerBound`.
set · iOS 18.0+
isPositive
TypeScript
set isPositive(value: boolean)
Swift declaration
var isPositive: Bool
Controls whether the format input is formatted as a positive or negative range.
When the range is formatted as a positive value, the returned string describes the time
from `lowerBound` to `upperBound`. When `isPositive` is set to `false`, the
returned string describes the time from `upperBound` to `lowerBound`.
The next discretization boundary after the given input.
Use this function to determine the next greater input that warrants updating the formatted output.
If ``isPositive`` is true, the returned range has the same `lowerBound` as the `input`,
but increases the `upperBound` so that the returned range produces the next greater output.
If ``isPositive`` is false, the returned range has the same `upperBound` as the `input`
and a greater `lowerBound`.
let style = Date.ComponentsFormatStyle(style: .wide)
print(style.format(start..<end)) // "1 hour"
guard let next = style.discreteInput(after: start..<end) else {
return
}
print(style.format(next)) // "1 hour, 1 second"
- Returns: If ``isPositive`` 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 ``FormatStyle/FormatOutput``. If ``isPositive`` is false, the range
`x..<input.upperBound`, where `x` is the smallest date that is greater than
`input.lowerBound` for which this style might produce a different
``FormatStyle/FormatOutput``. The function may return `nil` if there is no such
value smaller or equal to `input.upperBound`.
The next discretization boundary before the given input.
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"
- Returns: 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 ``FormatStyle/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
``FormatStyle/FormatOutput``.
The next input value after the given input.
If ``isPositive`` is true, the next input value maintains the same `lowerBound` as
`input`, but has a different`upperBound`. If ``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(before:)`` is
precise enough for your use case for any input `y`:
guard let x = style.discreteInput(before: y) else {
return
}
let z = style.input(after: x) ?? y
If the distance between the `upperBound`s of `x` and `z` 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.
- Returns: If ``isPositive`` is true, the range `input.lowerBound..<x`, where `x` is
the next larger date that this style can differentiate. If ``isPositive`` is false, the range
`x..<input.upperBound`, where `x` is the next higher date this style can differentiate, or
`nil` if there is no such `x`.
The next input value before the given input.
If ``isPositive`` is true, the next input value maintains the same `lowerBound` as
`input`, but has a different`upperBound`. If ``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:)`` 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.
- Returns: If ``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`` is false, the range
`x..<input.upperBound`, where `x` is the next smaller date this style can differentiate.
Shows the date interval with the specified style and the specified date and time fields.
- Parameters:
- style: The style for the field names.
- locale: The locale for formatting the date interval. May affect the language in which the formatted fields are displayed and how the individual fields are connected.
- calendar: The calendar to interpret date values.
- fields: The fields to be included in the output string. Chosen automatically based on the interval being formatted if unspecified. Fields with 0 value are dropped.
get · iOS 15.0+
style
TypeScript
get style(): Date_ComponentsFormatStyle_Style
Swift declaration
var style: Date.ComponentsFormatStyle.Style
set · iOS 15.0+
style
TypeScript
set style(value: Date_ComponentsFormatStyle_Style)
Swift declaration
var style: Date.ComponentsFormatStyle.Style
get · iOS 15.0+
fields
TypeScript
get fields(): (Array<Date_ComponentsFormatStyle_Field>) | null
Swift declaration
var fields: Set<Date.ComponentsFormatStyle.Field>?
set · iOS 15.0+
fields
TypeScript
set fields(value: (Array<Date_ComponentsFormatStyle_Field>) | null)
Swift declaration
var fields: Set<Date.ComponentsFormatStyle.Field>?
method · iOS 15.0+
format
TypeScript
format(v: SDKHandle): string
Swift declaration
func format(_ v: Range<Date>) -> String
Formats a value, using this style.
Use this method when you want to create a single style instance, and then use it to format
multiple values.
- Parameter value: The value to format.
- Returns: A representation of `value`, in the ``FormatOutput`` type, formatted according to
the style's configuration.
Modifies the format style to use the specified locale.
Use this format style to change the locale used by an existing format style.
- Parameter locale: The locale to apply to the format style.
- Returns: A format style modified to use the provided locale.