Pattern
The units to display a Duration with and configurations for the units.
- iOS
- 16.0+
- macOS
- 13.0+
- tvOS
- 16.0+
- watchOS
- 9.0+
struct Pattern
The units to display a Duration with and configurations for the units.
struct Pattern
ss8DurationV30FoundationInternationalizationE15TimeFormatStyleV7PatternV
What are these?7WU5A
import FoundationInternationalization
import Swift
struct TimeFormatStyle
Format style to format a Duration
in a localized positional format. For example, one hour and ten minutes is displayed as “1:10:00” in the U.S. English locale, or “1.10.00” in the Finnish locale.
@frozen struct Duration
A representation of high precision time.
init(from decoder: any Decoder) throws
init(pattern: Duration.TimeFormatStyle.Pattern, locale: Locale = .autoupdatingCurrent)
Creates an instance using the provided pattern and locale.
var attributed: Duration.TimeFormatStyle.Attributed { get }
The attributed format style corresponding to this style.
var grouping: NumberFormatStyleConfiguration.Grouping { get set }
The grouping
rule applied to high number values on the largest field in the pattern.
var locale: Locale { get set }
The locale to use when formatting the duration.
var pattern: Duration.TimeFormatStyle.Pattern { get set }
The pattern to display a Duration with.
func discreteInput(after input: Duration) -> Duration?
func discreteInput(before input: Duration) -> Duration?
func format(_ value: Duration) -> String
Creates a locale-aware string representation from a duration value.
func grouping(_ grouping: NumberFormatStyleConfiguration.Grouping) -> Duration.TimeFormatStyle
Returns a modified style that applies the given grouping
rule to the highest field in the pattern.
func locale(_ locale: Locale) -> Duration.TimeFormatStyle
Modifies the format style to use the specified locale.
@dynamicMemberLookup struct Attributed
Formats a duration as an attributed string with the durationField
attribute key and FoundationAttributes.DurationFieldAttribute
attribute.
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 hourMinute: Duration.TimeFormatStyle.Pattern { get }
Displays a duration in hours and minutes.
static var hourMinuteSecond: Duration.TimeFormatStyle.Pattern { get }
Displays a duration in hours, minutes, and seconds.
static var minuteSecond: Duration.TimeFormatStyle.Pattern { get }
Displays a duration in minutes and seconds. For example, one hour is formatted as “60:00” in en_US locale.
static func hourMinute(padHourToLength: Int, roundSeconds: FloatingPointRoundingRule = .toNearestOrEven) -> Duration.TimeFormatStyle.Pattern
Displays a duration in terms of hours and minutes with the specified configurations.
static func hourMinuteSecond(padHourToLength: Int, fractionalSecondsLength: Int = 0, roundFractionalSeconds: FloatingPointRoundingRule = .toNearestOrEven) -> Duration.TimeFormatStyle.Pattern
Displays a duration in terms of hours, minutes, and seconds with the specified configurations.
static func minuteSecond(padMinuteToLength: Int, fractionalSecondsLength: Int = 0, roundFractionalSeconds: FloatingPointRoundingRule = .toNearestOrEven) -> Duration.TimeFormatStyle.Pattern
Displays a duration in minutes and seconds with the specified configurations.
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.