PostgresTimestampWithTimeZone
public struct PostgresTimestampWithTimeZone:
PostgresValueConvertible, Equatable, Decodable, CustomStringConvertible
Represents a Postgres TIMESTAMP WITH TIME ZONE value, which consists of the following
components:
- year
- month
- day
- hour
- minute
- seconds (and fractional seconds)
- time zone (expressed as an offset from UTC/GMT)
For example, 2019-03-14 16:25:19.365+00:00.
Like Postgres itself, PostgresClientKit normalizes TIMESTAMP WITH TIME ZONE values by
converting them to UTC/GMT. The values are thus simply moments in time and representable
by Foundation Date instances.
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
PostgresTimestampWithTimeZonefrom components.For example, to represent
2019-03-14 16:25:19.365+00:00:let moment = PostgresTimestampWithTimeZone(year: 2019, month: 3, day: 14, hour: 16, minute: 25, second: 19, nanosecond: 365000000, timeZone: TimeZone(secondsFromGMT: 0)!)Declaration
Swift
public init?(year: Int, month: Int, day: Int, hour: Int, minute: Int, second: Int, nanosecond: Int = 0, timeZone: TimeZone)Parameters
yearthe year value
monththe month value (1 for January, 2 for February, and so on)
daythe day value
hourthe hour value
minutethe minute value
secondthe second value
nanosecondthe nanosecond value
timeZonethe time zone in which to interpret these components
-
Creates a
PostgresTimestampWithTimeZonefrom aDate.(Foundation
Dateinstances represent moments in time, not (year, month, day) tuples.)Declaration
Swift
public init(date: Date)Parameters
datethe moment in time
-
Creates a
PostgresTimestampWithTimeZonefrom a string.The string must conform to either the date format pattern
yyyy-MM-dd HH:mm:ss.SSSxxxxx(for example,2019-03-14 16:25:19.365+00:00) oryyyy-MM-dd HH:mm:ssxxxxx(for example,2019-03-14 16:25:19+00:00).Declaration
Swift
public init?(_ string: String)Parameters
stringthe string
-
A
DateComponentsfor thisPostgresTimestampWithTimeZone.The returned value has the following components set:
calendaryearmonthdayhourminutesecondnanosecondtimeZone
Declaration
Swift
public var dateComponents: DateComponents { get } -
A
Datefor thisPostgresTimestampWithTimeZone.(Foundation
Dateinstances represent moments in time, not (year, month, day) tuples.)Declaration
Swift
public var date: Date { get }
-
A
PostgresValuefor thisPostgresTimestampWithTimeZone.Declaration
Swift
public var postgresValue: PostgresValue { get }
-
True if
lhs.postgresValue == rhs.postgresValue.Declaration
Swift
public static func == (lhs: PostgresTimestampWithTimeZone, rhs: PostgresTimestampWithTimeZone) -> Bool
-
Declaration
Swift
public init(from decoder: Decoder) throws
-
A string representation of this
PostgresTimestampWithTimeZone.Equivalent to
String(describing: postgresValue).Declaration
Swift
public var description: String { get }