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
PostgresTimeWithTimeZonefrom 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 ZONEvalues 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
hourthe hour value
minutethe minute value
secondthe second value
nanosecondthe nanosecond value
timeZonethe time zone in which to interpret these components
-
Creates a
PostgresTimeWithTimeZoneby interpreting aDatein a specified time zone to obtain the hour, minute, second, and fractional second components, discarding the year, month, and day components.(Foundation
Dateinstances 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 ZONEvalues 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
datethe moment in time
timeZonethe time zone in which to interpret that moment
-
Creates a
PostgresTimeWithTimeZonefrom 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
stringthe string
-
A
DateComponentsfor thisPostgresTimeWithTimeZone.The returned value has the following components set:
hourminutesecondnanosecondtimeZone
Declaration
Swift
public var dateComponents: DateComponents { get } -
A
Datefor thisPostgresTimeWithTimeZone, created by 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 var date: Date { get }Parameters
timeZonethe time zone
Return Value
the moment in time
-
The time zone in which this
PostgresTimeWithTimeZonewas specified.Declaration
Swift
public var timeZone: TimeZone { get }
-
A
PostgresValuefor 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 }