PolarPlainDate
public struct PolarPlainDate
extension PolarPlainDate: CustomStringConvertible
extension PolarPlainDate: ExpressibleByStringLiteral
extension PolarPlainDate: Decodable
extension PolarPlainDate: Encodable
From https://bootstragram.com/blog/date-with-no-time-operations-swift A string that represents dates using their ISO 8601 representations.
PolarPlainDate
is a way to handle dates with no time — such as 2022-03-02
for March 2nd of 2022 — to
perform operations with convenience including adding days, dealing with ranges, etc.
-
Returns a date string initialized using their ISO 8601 representation.
Declaration
Swift
public init?(from dateAsString: String, calendar: Calendar = .current)
Parameters
dateAsString
The ISO 8601 representation of the date. For instance,
2022-03-02
for March 2nd of 2022.calendar
The calendar — including the time zone — to use. The default is the current calendar.
Return Value
A date string, or
nil
if a valid date could not be created fromdateAsString
. -
Returns a date string initialized using their ISO 8601 representation.
Declaration
Swift
public init(date: Date, calendar: Calendar = .current)
Parameters
date
The date to represent.
calendar
The calendar — including the time zone — to use. The default is the current calendar.
-
A string description of the
PlainDate
in ISO 8601 format.Declaration
Swift
public var description: String { get }
-
Declaration
Swift
public init(stringLiteral value: String)
-
Declaration
Swift
public init(from decoder: Decoder) throws
-
Declaration
Swift
public func encode(to encoder: Encoder) throws