DatabaseDateEncodingStrategy
public enum DatabaseDateEncodingStrategy
DatabaseDateEncodingStrategy
specifies how EncodableRecord
types that
also adopt the standard Encodable
protocol encode their Date
properties.
For example:
struct Player: EncodableRecord, Encodable {
static let databaseDateEncodingStrategy = DatabaseDateEncodingStrategy.timeIntervalSince1970
var name: String
var registrationDate: Date // encoded as an epoch timestamp
}
-
The strategy that uses formatting from the Date structure.
It encodes dates using the format “YYYY-MM-DD HH:MM:SS.SSS” in the UTC time zone.
Declaration
Swift
case deferredToDate
-
Encodes a Double: the number of seconds between the date and midnight UTC on 1 January 2001
Declaration
Swift
case timeIntervalSinceReferenceDate
-
Encodes a Double: the number of seconds between the date and midnight UTC on 1 January 1970
Declaration
Swift
case timeIntervalSince1970
-
Encodes an Int64: the number of seconds between the date and midnight UTC on 1 January 1970
Declaration
Swift
case secondsSince1970
-
Encodes an Int64: the number of milliseconds between the date and midnight UTC on 1 January 1970
Declaration
Swift
case millisecondsSince1970
-
Encodes dates according to the ISO 8601 and RFC 3339 standards
Declaration
Swift
case iso8601
-
Encodes a String, according to the provided formatter
Declaration
Swift
case formatted(DateFormatter)
-
Encodes the result of the user-provided function
Declaration
Swift
case custom((Date) -> DatabaseValueConvertible?)