PostgresTimeWithTimeZone
public struct PostgresTimeWithTimeZone:
PostgresValueConvertible, Equatable, Decodable, CustomStringConvertible
Represents a Postgres TIME WITH TIME ZONE
value, which consists of the following components:
- hour
- minute
- seconds (and fractional seconds)
- time zone (expressed as an offset from UTC/GMT)
For example, 20:10:05.128-07:00
.
Unlike TIMESTAMP WITH TIME ZONE
, a TIME WITH TIME ZONE
value is not normalized to UTC/GMT;
the time zone in which it is specified is preserved.
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
PostgresTimeWithTimeZone
from components.For example, to represent
20:10:05.128-07:00
:let time = PostgresTimeWithTimeZone(hour: 20, minute: 10, second: 05, nanosecond: 128000000, timeZone: TimeZone(secondsFromGMT: -7 * 60 * 60)!)
The specified time zone must have a fixed offset from UTC/GMT; its offset must not change due to daylight savings time. (This requirement is a consequence of
TIME WITH TIME ZONE
values not having the year, month, and day components required to determine whether daylight savings time is in effect.)Declaration
Swift
public init?(hour: Int, minute: Int, second: Int, nanosecond: Int = 0, timeZone: TimeZone)
Parameters
hour
the hour value
minute
the minute value
second
the second value
nanosecond
the nanosecond value
timeZone
the time zone in which to interpret these components
-
Creates a
PostgresTimeWithTimeZone
by interpreting aDate
in a specified time zone to obtain the hour, minute, second, and fractional second components, discarding the year, month, and day components.(Foundation
Date
instances represent moments in time, not (year, month, day) tuples.)The specified time zone must have a fixed offset from UTC/GMT; its offset must not change due to daylight savings time. (This requirement is a consequence of
TIME WITH TIME ZONE
values not having the year, month, and day components required to determine whether daylight savings time is in effect.)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
PostgresTimeWithTimeZone
from a string.The string must conform to either the date format pattern
HH:mm:ss.SSSxxxxx
(for example,20:10:05.128-07:00
) orHH:mm:ssxxxxx
(for example,20:10:05-07:00
).Declaration
Swift
public init?(_ string: String)
Parameters
string
the string
-
A
DateComponents
for thisPostgresTimeWithTimeZone
.The returned value has the following components set:
hour
minute
second
nanosecond
timeZone
Declaration
Swift
public var dateComponents: DateComponents { get }
-
A
Date
for thisPostgresTimeWithTimeZone
, created by 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 var date: Date { get }
Parameters
timeZone
the time zone
Return Value
the moment in time
-
The time zone in which this
PostgresTimeWithTimeZone
was specified.Declaration
Swift
public var timeZone: TimeZone { get }
-
A
PostgresValue
for thisPostgresTimeWithTimeZone
.Declaration
Swift
public var postgresValue: PostgresValue { get }
-
True if
lhs.postgresValue == rhs.postgresValue
.Declaration
Swift
public static func == (lhs: PostgresTimeWithTimeZone, rhs: PostgresTimeWithTimeZone) -> Bool
-
Declaration
Swift
public init(from decoder: Decoder) throws
-
A string representation of this
PostgresTimeWithTimeZone
.Equivalent to
String(describing: postgresValue)
.Declaration
Swift
public var description: String { get }