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
PostgresTimestampWithTimeZone
from 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
year
the year value
month
the month value (1 for January, 2 for February, and so on)
day
the day value
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
PostgresTimestampWithTimeZone
from aDate
.(Foundation
Date
instances represent moments in time, not (year, month, day) tuples.)Declaration
Swift
public init(date: Date)
Parameters
date
the moment in time
-
Creates a
PostgresTimestampWithTimeZone
from 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
string
the string
-
A
DateComponents
for thisPostgresTimestampWithTimeZone
.The returned value has the following components set:
calendar
year
month
day
hour
minute
second
nanosecond
timeZone
Declaration
Swift
public var dateComponents: DateComponents { get }
-
A
Date
for thisPostgresTimestampWithTimeZone
.(Foundation
Date
instances represent moments in time, not (year, month, day) tuples.)Declaration
Swift
public var date: Date { get }
-
A
PostgresValue
for 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 }