Unit
Units that a duration can be displayed as with UnitsFormatStyle
.
- iOS
- 16.0+
- macOS
- 13.0+
- tvOS
- 16.0+
- watchOS
- 9.0+
struct Unit
Units that a duration can be displayed as with UnitsFormatStyle
.
struct Unit
ss8DurationV30FoundationInternationalizationE16UnitsFormatStyleV4UnitV
What are these?4HKIV
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.
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 valueLengthLimits: Range<Int>?
The padding or truncating behavior of the unit value.
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 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.
protocol Decodable
A type that can decode itself from an external representation.
protocol Encodable
A type that can encode itself to an external representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
protocol Sendable
init(from decoder: any Decoder) throws
static var days: Duration.UnitsFormatStyle.Unit { get }
The unit for days. One day is always 86400 seconds.
static var hours: Duration.UnitsFormatStyle.Unit { get }
The unit for hours. One day is 3600 seconds.
static var microseconds: Duration.UnitsFormatStyle.Unit { get }
The unit for microseconds.
static var milliseconds: Duration.UnitsFormatStyle.Unit { get }
The unit for milliseconds.
static var minutes: Duration.UnitsFormatStyle.Unit { get }
The unit for minutes. One minute is 60 seconds.
static var nanoseconds: Duration.UnitsFormatStyle.Unit { get }
The unit for nanoseconds.
static var seconds: Duration.UnitsFormatStyle.Unit { get }
The unit for seconds.
static var weeks: Duration.UnitsFormatStyle.Unit { get }
The unit for weeks. One week is always 604800 seconds.
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.