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

Commit

Permalink
Merge pull request #44 from pruthvikar/pruthvikar-patch-1-reference-d…
Browse files Browse the repository at this point in the history
…ate-fix-1

Replace `calendar.timeZone = TimeZone(abbreviation: "UTC")!` because it crashes on Linux.
  • Loading branch information
natebird authored May 20, 2017
2 parents 5070e7d + f3eee22 commit bfddfcb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions Sources/PostgreSQL/Bind/BinaryUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,12 @@ struct BinaryUtils {
}

// MARK: - Date / Time

struct TimestampConstants {
static let referenceDate: Date = {
let components = DateComponents(year: 2000, month: 1, day: 1)
var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = TimeZone(abbreviation: "UTC")!
return calendar.date(from: components)!
}()
// 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 {
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.timeIntervalSince(BinaryUtils.TimestampConstants.referenceDate)
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 bfddfcb

Please sign in to comment.