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.

  • Encodes a Double: the number of seconds between the date and midnight UTC on 1 January 2001

  • Encodes a Double: the number of seconds between the date and midnight UTC on 1 January 1970

  • Encodes an Int64: the number of seconds between the date and midnight UTC on 1 January 1970

  • Encodes an Int64: the number of milliseconds between the date and midnight UTC on 1 January 1970

  • Encodes dates according to the ISO 8601 and RFC 3339 standards

  • Encodes a String, according to the provided formatter

  • Encodes the result of the user-provided function