PostgresTime

public struct PostgresTime:
    PostgresValueConvertible, Equatable, Decodable, CustomStringConvertible

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

  • hour
  • minute
  • seconds (and fractional seconds)

For example, 16:25:19.365.

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 PostgresTime from components.

    For example, to represent 16:25:19.365:

    let time = PostgresTime(hour: 16,
                            minute: 25,
                            second: 19,
                            nanosecond: 365000000)
    

    Declaration

    Swift

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

    Parameters

    hour

    the hour value

    minute

    the minute value

    second

    the second value

    nanosecond

    the nanosecond value

  • Creates a PostgresTime by interpreting a Date in a specified time zone to obtain the hour, minute, second, and fractional second components, and discarding the year, month, and day 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 PostgresTime from a string.

    The string must conform to either the date format pattern HH:mm:ss.SSS (for example, 16:25:19.365) or HH:mm:ss (for example, 16:25:19).

    Declaration

    Swift

    public init?(_ string: String)

    Parameters

    string

    the string

  • A DateComponents for this PostgresTime.

    The returned value has the following components set:

    • hour
    • minute
    • second
    • nanosecond

    Declaration

    Swift

    public var dateComponents: DateComponents { get }
  • Creates a Date by interpreting this PostgresTime in a specified time zone, setting the year component to 2000 and the month and day components to 1.

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

    Swift

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

    Equivalent to String(describing: postgresValue).

    Declaration

    Swift

    public var description: String { get }