PostgresDate

public struct PostgresDate:
    PostgresValueConvertible, Equatable, Decodable, CustomStringConvertible

Represents a Postgres DATE value, which consists of the following components:

  • year
  • month
  • day

For example, 2019-03-14.

  • Creates a PostgresDate from components.

    For example, to represent 2019-03-14:

    let date = PostgresDate(year: 2019,
                            month: 3,
                            day: 14)
    

    Declaration

    Swift

    public init?(year: Int,
                 month: Int,
                 day: Int)

    Parameters

    year

    the year value

    month

    the month value (1 for January, 2 for February, and so on)

    day

    the day value

  • Creates a PostgresDate by interpreting a Date in a specified time zone to obtain the year, month, and day components, and discarding the hour, minute, second, and fractional second components.

    (Foundation Date instances represent moments in time, not (year, month, day) tuples.)

    Declaration

    Swift

    public init(date: Date, in timeZone: TimeZone)

    Parameters

    date

    the moment in time

    timeZone

    the time zone in which to interpret that moment

  • Creates a PostgresDate from a string.

    The string must conform to the date format pattern yyyy-MM-dd. For example, 2019-03-14.

    Declaration

    Swift

    public init?(_ string: String)

    Parameters

    string

    the string

  • A DateComponents value for this PostgresDate.

    The returned value has the following components set:

    • year
    • month
    • day

    Declaration

    Swift

    public var dateComponents: DateComponents { get }
  • Creates a Date by interpreting this PostgresDate in a specified time zone, setting the hour, minute, second, and fractional second components to 0.

    (Foundation Date instances represent moments in time, not (year, month, day) tuples.)

    Declaration

    Swift

    public func date(in timeZone: TimeZone) -> Date

    Parameters

    timeZone

    the time zone

    Return Value

    the moment in time

  • True if lhs.postgresValue == rhs.postgresValue.

    Declaration

    Swift

    public static func == (lhs: PostgresDate, rhs: PostgresDate) -> Bool
  • Declaration

    Swift

    public init(from decoder: Decoder) throws
  • A string representation of this PostgresDate.

    Equivalent to String(describing: postgresValue).

    Declaration

    Swift

    public var description: String { get }