valueLengthLimits
The padding or truncating behavior of the unit value.
- iOS
- 16.0+
- macOS
- 13.0+
- tvOS
- 16.0+
- watchOS
- 9.0+
var valueLengthLimits: Range<Int>?
For example, set this to 2...
to force 2-digit padding on all units.
The padding or truncating behavior of the unit value.
var valueLengthLimits: Range<Int>?
ss8DurationV30FoundationInternationalizationE16UnitsFormatStyleV17valueLengthLimitsSnySiGSgvp
What are these?1RD0M
For example, set this to 2...
to force 2-digit padding on all units.
import Swift
import FoundationInternationalization
struct UnitsFormatStyle
A FormatStyle
that displays a duration as a list of duration units, such as “2 hours, 43 minutes, 26 seconds” in English.
@frozen struct Duration
A representation of high precision time.
@frozen struct Range<Bound> where Bound : Comparable
A half-open interval from a lower bound up to, but not including, an upper bound.
@frozen struct Int
A signed integer value type.
init(allowedUnits: Set<Duration.UnitsFormatStyle.Unit>, width: Duration.UnitsFormatStyle.UnitWidth, maximumUnitCount: Int? = nil, zeroValueUnits: Duration.UnitsFormatStyle.ZeroValueUnitsDisplayStrategy = .hide, valueLength: Int? = nil, fractionalPart: Duration.UnitsFormatStyle.FractionalPartDisplayStrategy = .hide)
Creates an instance using the provided specifications.
init<ValueRange>(allowedUnits: Set<Duration.UnitsFormatStyle.Unit>, width: Duration.UnitsFormatStyle.UnitWidth, maximumUnitCount: Int? = nil, zeroValueUnits: Duration.UnitsFormatStyle.ZeroValueUnitsDisplayStrategy = .hide, valueLengthLimits: ValueRange, fractionalPart: Duration.UnitsFormatStyle.FractionalPartDisplayStrategy = .hide) where ValueRange : RangeExpression, ValueRange.Bound == Int
Creates an instance using the provided specifications.
init(from decoder: any Decoder) throws
var allowedUnits: Set<Duration.UnitsFormatStyle.Unit>
The units that may be included in the output string.
var attributed: Duration.UnitsFormatStyle.Attributed { get }
Returns a Duration.UnitsFormatStyle.Attributed
style to format a duration as an attributed string using the configuration of this format style. Units in the string are annotated with the durationField
and measurement
attribute keys and the DurationFieldAttribute
and MeasurementAttribute
attribute values.
var fractionalPartDisplay: Duration.UnitsFormatStyle.FractionalPartDisplayStrategy
The strategy for displaying a duration if it cannot be represented exactly with the allowed units.
var locale: Locale
The locale to use when formatting the duration.
var maximumUnitCount: Int?
The maximum number of time units to include in the output string.
var unitWidth: Duration.UnitsFormatStyle.UnitWidth
The width of the unit and the spacing between the value and the unit.
var zeroValueUnitsDisplay: Duration.UnitsFormatStyle.ZeroValueUnitsDisplayStrategy
The strategy for how zero-value units are handled.
func discreteInput(after input: Duration) -> Duration?
func discreteInput(before input: Duration) -> Duration?
func format(_ duration: Duration) -> String
Creates a locale-aware string representation from a duration value.
func locale(_ locale: Locale) -> Duration.UnitsFormatStyle
A modifier to set the locale of the format style.
@dynamicMemberLookup struct Attributed
A format style to format a duration as an attributed string. Units in the string are annotated with the durationField
and measurement
attribute keys and the DurationFieldAttribute
and MeasurementAttribute
attribute values.
struct FractionalPartDisplayStrategy
Specifies how a duration is displayed if it cannot be represented exactly with the allowed units.
struct Unit
Units that a duration can be displayed as with UnitsFormatStyle
.
struct UnitWidth
Specifies the width of the unit and the spacing of the value and the unit.
struct ZeroValueUnitsDisplayStrategy
Specifies how zero value units are handled.