ParseStrategy
Options for parsing string representations of dates to create a Date
instance.
- iOS
- 15.0+
- macOS
- 12.0+
- tvOS
- 15.0+
- watchOS
- 8.0+
struct ParseStrategy
Options for parsing string representations of dates to create a Date
instance.
struct ParseStrategy
s20FoundationEssentials4DateV0A20InternationalizationE13ParseStrategyV
What are these?3Y9R1
import FoundationInternationalization
import FoundationEssentials
struct Date
Date
represents a single point in time.
func formatted() -> String
func formatted(date: Date.FormatStyle.DateStyle, time: Date.FormatStyle.TimeStyle) -> String
Converts self
to its textual representation that contains both the date and time parts. The exact format depends on the user’s preferences.
struct AnchoredRelativeFormatStyle
A relative format style that is detached from the system time, and instead formats an anchor date relative to the format input.
struct AttributedStyle
struct ComponentsFormatStyle
struct FormatString
struct FormatStyle
Strategies for formatting a Date
.
struct IntervalFormatStyle
struct RelativeFormatStyle
struct VerbatimFormatStyle
Formats a Date
using the given format.
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol CustomConsumingRegexComponent : RegexComponent
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 Escapable
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
protocol ParseStrategy : Decodable, Encodable, Hashable
A type that can parse a representation of a given data type.
protocol RegexComponent<RegexOutput>
A type that represents a regular expression.
protocol Sendable
init(format: Date.FormatString, locale: Locale? = nil, timeZone: TimeZone, calendar: Calendar = Calendar(identifier: .gregorian), isLenient: Bool = true, twoDigitStartDate: Date = Date(timeIntervalSince1970: 0))
Creates a new ParseStrategy
with the given configurations.
init(from decoder: any Decoder) throws
var calendar: Calendar
The calendar to use when parsing date strings and creating the date.
var format: String { get }
The string representation of the fixed format conforming to Unicode Technical Standard #35.
var isLenient: Bool
Indicates whether to use heuristics when parsing the representation.
var locale: Locale?
The locale to use when parsing date strings with the specified format. Use system locale if unspecified.
var timeZone: TimeZone
The time zone to use for creating the date.
var twoDigitStartDate: Date
The earliest date that can be denoted by a two-digit year specifier.
func consuming(_ input: String, startingAt index: String.Index, in bounds: Range<String.Index>) throws -> (upperBound: String.Index, output: Date)?
func parse(_ value: String) throws -> Date
Returns a Date
of a given string interpreted using the current settings.
typealias RegexOutput = Date
static func date(_ style: Date.FormatStyle.DateStyle, locale: Locale, timeZone: TimeZone, calendar: Calendar? = nil) -> Date.ParseStrategy
Creates a regex component to match a localized date string and capture the string as a Date
. The string is expected to follow the format of what Date.FormatStyle(date:locale:calendar:)
produces. Date
created by this regex component would be at 00:00:00 in the specified time zone.
static func date(format: Date.FormatString, locale: Locale, timeZone: TimeZone, calendar: Calendar? = nil, twoDigitStartDate: Date = Date(timeIntervalSince1970: 0)) -> Self
Creates a regex component to match a localized date string following the specified format and capture the string as a Date
.
static func dateTime(date: Date.FormatStyle.DateStyle, time: Date.FormatStyle.TimeStyle, locale: Locale, timeZone: TimeZone, calendar: Calendar? = nil) -> Date.ParseStrategy
Creates a regex component to match a localized date and time string and capture the string as a Date
. The date string is expected to follow the format of what Date.FormatStyle(date:time:locale:calendar:)
produces.
static func fixed(format: Date.FormatString, timeZone: TimeZone, locale: Locale? = nil) -> Self where Self == Date.ParseStrategy
var regex: Regex<Self.RegexOutput> { get }
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.
typealias DateStyle = Date.FormatStyle.DateStyle
typealias TimeStyle = Date.FormatStyle.TimeStyle