PostgresTimestamp

public struct PostgresTimestamp:
    PostgresValueConvertible, Equatable, Decodable, CustomStringConvertible

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

  • year
  • month
  • day
  • hour
  • minute
  • seconds (and fractional seconds)

For example, 2019-03-14 16:25:19.365.

Unlike TIMESTAMP WITH TIME ZONE, a TIMESTAMP value does not have a time zone component. Consequently, it does not, by itself, represent a specific moment in time. For example, if two persons in different time zones wished to schedule a telephone call, the call’s starting time could not be unambiguously recorded by a TIMESTAMP value because it would not indicate in which time zone the date and time components are to be interpreted.

(For this reason, TIMESTAMP WITH TIME ZONE is often a more useful data type. See PostgresTimestampWithTimeZone.)

Like Foundation DateComponents, PostgresClientKit records fractional seconds in nanoseconds. However, due to a bug in the Foundation DateFormatter class, only 3 fractional digits are preserved (millisecond resolution) in values sent to and received from the Postgres server.

  • Creates a PostgresTimestamp from components.

    For example, to represent 2019-03-14 16:25:19.365:

    let timestamp = PostgresTimestamp(year: 2019,
                                      month: 3,
                                      day: 14,
                                      hour: 16,
                                      minute: 25,
                                      second: 19,
                                      nanosecond: 365000000)
    

    Declaration

    Swift

    public init?(year: Int,
                 month: Int,
                 day: Int,
                 hour: Int,
                 minute: Int,
                 second: Int,
                 nanosecond: Int = 0)

    Parameters

    year

    the year value

    month

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

    day

    the day value

    hour

    the hour value

    minute

    the minute value

    second

    the second value

    nanosecond

    the nanosecond value

  • Creates a PostgresTimestamp by interpreting a Date in a specified time zone.

    (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 PostgresTimestamp from a string.

    The string must conform to either the date format pattern yyyy-MM-dd HH:mm:ss.SSS (for example, 2019-03-14 16:25:19.365) or yyyy-MM-dd HH:mm:ss (for example, 2019-03-14 16:25:19) .

    Declaration

    Swift

    public init?(_ string: String)

    Parameters

    string

    the string

  • A DateComponents for this PostgresTimestamp.

    The returned value has the following components set:

    • year
    • month
    • day
    • hour
    • minute
    • second
    • nanosecond

    Declaration

    Swift

    public var dateComponents: DateComponents { get }
  • Creates a Date by interpreting this PostgresTimestamp in a specified time zone.

    (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: PostgresTimestamp, rhs: PostgresTimestamp) -> Bool
  • Declaration

    Swift

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

    Equivalent to String(describing: postgresValue).

    Declaration

    Swift

    public var description: String { get }