Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
Changed reference date to correct year (2000 as opposed to 2001)
Browse files Browse the repository at this point in the history
  • Loading branch information
pruthvikar committed May 19, 2017
1 parent 08aa394 commit f3eee22
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion Sources/PostgreSQL/Bind/BinaryUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ struct BinaryUtils {
}

// MARK: - Date / Time

struct TimestampConstants {
// Foundation referenceDate is 00:00:00 UTC on 1 January 2001,
// the reference date we want is 00:00:00 UTC on 1 January 2000
static let offsetTimeIntervalSinceFoundationReferenceDate: TimeInterval = -31_622_400
static let referenceDate = Date(timeIntervalSinceReferenceDate: offsetTimeIntervalSinceFoundationReferenceDate)
}

static func parseTimetamp(value: UnsafeMutablePointer<Int8>, isInteger: Bool) -> Date {
let interval: TimeInterval
Expand All @@ -225,7 +232,7 @@ struct BinaryUtils {
let seconds = parseFloat64(value :value)
interval = TimeInterval(seconds)
}
return Date(timeIntervalSinceReferenceDate: interval)
return Date(timeInterval: interval, since: TimestampConstants.referenceDate)
}

// MARK: - Interval
Expand Down
4 changes: 2 additions & 2 deletions Sources/PostgreSQL/Bind/Bind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ public final class Bind {
Creates an input binding from a Date.
*/
public convenience init(date: Date, configuration: Configuration) {
let interval = date.timeIntervalSinceReferenceDate
let interval = date.timeIntervalSince(BinaryUtils.TimestampConstants.referenceDate)

if configuration.hasIntegerDatetimes {
let microseconds = Int64(interval * 1_000_000)
var value = microseconds.bigEndian
Expand Down

0 comments on commit f3eee22

Please sign in to comment.