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
PostgresTimefrom 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
hourthe hour value
minutethe minute value
secondthe second value
nanosecondthe nanosecond value
-
Creates a
PostgresTimeby interpreting aDatein a specified time zone to obtain the hour, minute, second, and fractional second components, and discarding the year, month, and day components.(Foundation
Dateinstances represent moments in time, not (year, month, day) tuples.)Declaration
Swift
public init(date: Date, in timeZone: TimeZone)Parameters
datethe moment in time
timeZonethe time zone in which to interpret that moment
-
Creates a
PostgresTimefrom a string.The string must conform to either the date format pattern
HH:mm:ss.SSS(for example,16:25:19.365) orHH:mm:ss(for example,16:25:19).Declaration
Swift
public init?(_ string: String)Parameters
stringthe string
-
A
DateComponentsfor thisPostgresTime.The returned value has the following components set:
hourminutesecondnanosecond
Declaration
Swift
public var dateComponents: DateComponents { get } -
Creates a
Dateby interpreting thisPostgresTimein a specified time zone, setting the year component to 2000 and the month and day components to 1.(Foundation
Dateinstances represent moments in time, not (year, month, day) tuples.)Declaration
Swift
public func date(in timeZone: TimeZone) -> DateParameters
timeZonethe time zone
Return Value
the moment in time
-
A
PostgresValuefor thisPostgresTime.Declaration
Swift
public var postgresValue: PostgresValue { get }
-
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 }