TemporalSpec
public protocol TemporalSpec
The TemporalSpec protocol defines an ISO-8601
formatted Date value. Types that conform to this protocol are responsible for providing
the parsing and formatting logic with the correct granularity.
-
A static builder that return an instance that represent the current point in time.
Declaration
Swift
static func now() -> Self -
The underlying
Dateobject. AllTemporalSpecimplementations must be backed by a FoundationDateinstance.Declaration
Swift
var foundationDate: Foundation.Date { get } -
The timezone field is an optional field used to specify the timezone associated with a particular date.
Declaration
Swift
var timeZone: TimeZone? { get } -
iso8601StringDefault implementationThe ISO-8601 formatted string in the UTC
TimeZone.See also
iso8601FormattedString(TemporalFormat, TimeZone) -> StringDefault Implementation
The ISO8601 representation of the scalar using
.fullas the format and.utcasTimeZone.See also
iso8601FormattedString(format:timeZone:)Declaration
Swift
var iso8601String: String { get } -
init(iso8601String:Default implementation) Parses an ISO-8601
Stringinto aTemporalSpec.Note
if no timezone is present in the string,
.autoupdatingCurrentis used.Parameters
- iso8601String: the string in the ISO8601 format
Throws
DataStoreError.decodeErrorin case the provided string is not formatted as expected by the scalar type.Important
This will cycle through all available formats for the concrete type. If you know the format, use
init(iso8601String:format:) throwsinstead.Default Implementation
Declaration
Swift
init(iso8601String: String) throws -
init(iso8601String:Default implementationformat: ) Parses an ISO-8601
Stringinto aTemporalSpec.Note
if no timezone is present in the string,
.autoupdatingCurrentis used.Parameters
- iso8601String: the string in the ISO8601 format
- format: The
TemporalFormatof theiso8601String
Throws
DataStoreError.decodeErrorin case the provided string is not formatted as expected by the scalar type.Default Implementation
Declaration
Swift
init(iso8601String: String, format: TemporalFormat) throws -
Constructs a
TemporalSpecfrom aDateobject.Declaration
Swift
init(_ date: Foundation.Date, timeZone: TimeZone?)Parameters
dateThe
Dateinstance that will be used as the reference of theTemporalSpecinstance. -
iso8601FormattedString(format:Default implementationtimeZone: ) A string representation of the underlying date formatted using ISO8601 rules.
Default Implementation
Create an iso8601
Stringwith the desired format option for this spec.Declaration
Swift
func iso8601FormattedString(format: TemporalFormat, timeZone: TimeZone) -> StringParameters
formatthe desired
TemporalFormat.timeZonethe target
TimeZoneReturn Value
the ISO8601 formatted string in the requested format
-
+(_:Extension method_: ) Add a
DateUnitto aTemporal.DateorTemporal.DateTimelet tomorrow = Temporal.Date.now() + .days(1)Declaration
Swift
static func + (left: Self, right: DateUnit) -> SelfParameters
leftrightDateUnitto add toleftReturn Value
A new
Temporal.DateorTemporal.DateTimetheDateUnitwas added to. -
-(_:Extension method_: ) Subtract a
DateUnitfrom aTemporal.DateorTemporal.DateTimelet yesterday = Temporal.Date.now() - .day(1)Declaration
Swift
static func - (left: Self, right: DateUnit) -> SelfParameters
leftrightDateUnitto subtract fromleftReturn Value
A new
Temporal.DateorTemporal.DateTimetheDateUnitwas subtracted from.
-
init(from:Extension method) Declaration
Swift
init(from decoder: Decoder) throws -
encode(to:Extension method) Declaration
Swift
func encode(to encoder: Encoder) throws
-
+(_:Extension method_: ) Add a
TimeUnitto aTemporal.TimeorTemporal.DateTimeDeclaration
Swift
static func + (left: Self, right: TimeUnit) -> SelfParameters
leftrightTimeUnitto add toleftReturn Value
A new
Temporal.TimeorTemporal.DateTimetheTimeUnitwas added to. -
-(_:Extension method_: ) Subtract a
TimeUnitfrom aTemporal.TimeorTemporal.DateTimeDeclaration
Swift
static func - (left: Self, right: TimeUnit) -> SelfParameters
leftrightTimeUnitto subtract fromleftReturn Value
A new
Temporal.TimeorTemporal.DateTimetheTimeUnitwas subtracted from.
View on GitHub