DatabaseDateDecodingStrategy
public enum DatabaseDateDecodingStrategy
DatabaseDateDecodingStrategy specifies how FetchableRecord types that also adopt the standard Decodable protocol decode their date properties.
For example:
struct Player: FetchableRecord, Decodable {
static let databaseDateDecodingStrategy: DatabaseDateDecodingStrategy = .timeIntervalSince1970
var name: String
var registrationDate: Date // decoded from epoch timestamp
}
-
The strategy that uses formatting from the Date structure.
It decodes numeric values as a number of seconds since Epoch (midnight UTC on January 1st, 1970).
It decodes strings in the following formats, assuming UTC time zone. Missing components are assumed to be zero:
YYYY-MM-DDYYYY-MM-DD HH:MMYYYY-MM-DD HH:MM:SSYYYY-MM-DD HH:MM:SS.SSSYYYY-MM-DDTHH:MMYYYY-MM-DDTHH:MM:SSYYYY-MM-DDTHH:MM:SS.SSS
Declaration
Swift
case deferredToDate -
Decodes numeric values as a number of seconds between the date and midnight UTC on 1 January 2001
Declaration
Swift
case timeIntervalSinceReferenceDate -
Decodes numeric values as a number of seconds between the date and midnight UTC on 1 January 1970
Declaration
Swift
case timeIntervalSince1970 -
Decodes numeric values as a number of milliseconds between the date and midnight UTC on 1 January 1970
Declaration
Swift
case millisecondsSince1970 -
Decodes dates according to the ISO 8601 standards
Declaration
Swift
case iso8601 -
Decodes a String, according to the provided formatter
Declaration
Swift
case formatted(DateFormatter) -
Decodes according to the user-provided function.
If the database value does not contain a suitable value, the function must return nil (GRDB will interpret this nil result as a conversion error, and react accordingly).
Declaration
Swift
case custom((DatabaseValue) -> Date?)
View on GitHub
Install in Dash
DatabaseDateDecodingStrategy Enumeration Reference