diff --git a/.gitignore b/.gitignore index a058f0c..56e95c2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ Packages Database *.xcodeproj Package.pins - +Package.resolved diff --git a/.travis.yml b/.travis.yml index 657eaff..1407d2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,8 @@ matrix: include: - os: osx osx_image: xcode8.3 + - os: osx + osx_image: xcode9 before_install: - gem install xcpretty diff --git a/Package.swift b/Package.swift index a08a3e4..425fbca 100644 --- a/Package.swift +++ b/Package.swift @@ -1,3 +1,4 @@ +// swift-tools-version:3.1 import PackageDescription let package = Package( diff --git a/Package@swift-4.swift b/Package@swift-4.swift new file mode 100644 index 0000000..0b88647 --- /dev/null +++ b/Package@swift-4.swift @@ -0,0 +1,23 @@ +// swift-tools-version:4.0 +import PackageDescription + +let package = Package( + name: "PostgreSQL", + products: [ + .library(name: "PostgreSQL", targets: ["PostgreSQL"]), + ], + dependencies: [ + // Module map for `libpq` + .package(url: "https://github.com/vapor-community/cpostgresql.git", .upToNextMajor(from: "2.1.0")), + + // Data structure for converting between multiple representations + .package(url: "https://github.com/vapor/node.git", .upToNextMajor(from: "2.1.0")), + + // Core extensions, type-aliases, and functions that facilitate common tasks + .package(url: "https://github.com/vapor/core.git", .upToNextMajor(from: "2.1.2")) + ], + targets: [ + .target(name: "PostgreSQL", dependencies: ["CPostgreSQL", "Node", "Core"]), + .testTarget(name: "PostgreSQLTests", dependencies: ["PostgreSQL"]), + ] +) diff --git a/Sources/PostgreSQL/Bind/BinaryUtils.swift b/Sources/PostgreSQL/Bind/BinaryUtils.swift index 13c7387..9162c90 100644 --- a/Sources/PostgreSQL/Bind/BinaryUtils.swift +++ b/Sources/PostgreSQL/Bind/BinaryUtils.swift @@ -306,9 +306,16 @@ struct BinaryUtils { digitIndex += 1 } - let endIndex = string.index(decimalIndex, offsetBy: dscale + 1) - string = string.substring(to: endIndex) - return string + #if swift(>=3.2) + let maxOffset = string.distance(from: decimalIndex, to: string.endIndex) + let offset = min(maxOffset, dscale) + let endIndex = string.index(decimalIndex, offsetBy: offset) + + return String(string[..=4.0) + return String(bitString[..=3.2) + XCTAssertEqual(timestamp.timeIntervalSince1970, parsedDate.timeIntervalSince1970, accuracy: 0.001) + #else + XCTAssertEqualWithAccuracy(timestamp.timeIntervalSince1970, parsedDate.timeIntervalSince1970, accuracy: 0.001) + #endif } } @@ -231,7 +236,12 @@ class BinaryUtilsTests: XCTestCase { for (hexString, timestamp) in floatTimestampTests { var bytes = hexString.hexStringBytes let parsedDate = BinaryUtils.parseTimetamp(value: &bytes, isInteger: false) - XCTAssertEqualWithAccuracy(timestamp.timeIntervalSince1970, parsedDate.timeIntervalSince1970, accuracy: 0.001) + + #if swift(>=3.2) + XCTAssertEqual(timestamp.timeIntervalSince1970, parsedDate.timeIntervalSince1970, accuracy: 0.001) + #else + XCTAssertEqualWithAccuracy(timestamp.timeIntervalSince1970, parsedDate.timeIntervalSince1970, accuracy: 0.001) + #endif } }