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
Date
object. AllTemporalSpec
implementations must be backed by a FoundationDate
instance.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 }
-
iso8601String
Default implementationThe ISO-8601 formatted string in the UTC
TimeZone
.See also
iso8601FormattedString(TemporalFormat, TimeZone) -> String
Default Implementation
The ISO8601 representation of the scalar using
.full
as the format and.utc
asTimeZone
.See also
iso8601FormattedString(format:timeZone:)
Declaration
Swift
var iso8601String: String { get }
-
init(iso8601String:
Default implementation) Parses an ISO-8601
String
into aTemporalSpec
.Note
if no timezone is present in the string,
.autoupdatingCurrent
is used.Parameters
- iso8601String: the string in the ISO8601 format
Throws
DataStoreError.decodeError
in 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:) throws
instead.Default Implementation
Declaration
Swift
init(iso8601String: String) throws
-
init(iso8601String:
Default implementationformat: ) Parses an ISO-8601
String
into aTemporalSpec
.Note
if no timezone is present in the string,
.autoupdatingCurrent
is used.Parameters
- iso8601String: the string in the ISO8601 format
- format: The
TemporalFormat
of theiso8601String
Throws
DataStoreError.decodeError
in 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
TemporalSpec
from aDate
object.Declaration
Swift
init(_ date: Foundation.Date, timeZone: TimeZone?)
Parameters
date
The
Date
instance that will be used as the reference of theTemporalSpec
instance. -
iso8601FormattedString(format:
Default implementationtimeZone: ) A string representation of the underlying date formatted using ISO8601 rules.
Default Implementation
Create an iso8601
String
with the desired format option for this spec.Declaration
Swift
func iso8601FormattedString(format: TemporalFormat, timeZone: TimeZone) -> String
Parameters
format
the desired
TemporalFormat
.timeZone
the target
TimeZone
Return Value
the ISO8601 formatted string in the requested format
-
+(_:
Extension method_: ) Add a
DateUnit
to aTemporal.Date
orTemporal.DateTime
let tomorrow = Temporal.Date.now() + .days(1)
Declaration
Swift
public static func + (left: Self, right: DateUnit) -> Self
Parameters
left
right
DateUnit
to add toleft
Return Value
A new
Temporal.Date
orTemporal.DateTime
theDateUnit
was added to. -
-(_:
Extension method_: ) Subtract a
DateUnit
from aTemporal.Date
orTemporal.DateTime
let yesterday = Temporal.Date.now() - .day(1)
Declaration
Swift
public static func - (left: Self, right: DateUnit) -> Self
Parameters
left
right
DateUnit
to subtract fromleft
Return Value
A new
Temporal.Date
orTemporal.DateTime
theDateUnit
was subtracted from.
-
init(from:
Extension method) Declaration
Swift
public init(from decoder: Decoder) throws
-
encode(to:
Extension method) Declaration
Swift
public func encode(to encoder: Encoder) throws
-
+(_:
Extension method_: ) Add a
TimeUnit
to aTemporal.Time
orTemporal.DateTime
Declaration
Swift
public static func + (left: Self, right: TimeUnit) -> Self
Parameters
left
right
TimeUnit
to add toleft
Return Value
A new
Temporal.Time
orTemporal.DateTime
theTimeUnit
was added to. -
-(_:
Extension method_: ) Subtract a
TimeUnit
from aTemporal.Time
orTemporal.DateTime
Declaration
Swift
public static func - (left: Self, right: TimeUnit) -> Self
Parameters
left
right
TimeUnit
to subtract fromleft
Return Value
A new
Temporal.Time
orTemporal.DateTime
theTimeUnit
was subtracted from.