From 5e59752322f8aff47b2f6b7ce333e423c7b27392 Mon Sep 17 00:00:00 2001 From: patrick-zippenfenig Date: Sun, 7 Aug 2022 14:15:58 +0200 Subject: [PATCH] option to set database path --- .../SwiftTimeZoneLookup/SwiftTimeZoneLookup.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftTimeZoneLookup/SwiftTimeZoneLookup.swift b/Sources/SwiftTimeZoneLookup/SwiftTimeZoneLookup.swift index ca0e4bf..b86e724 100644 --- a/Sources/SwiftTimeZoneLookup/SwiftTimeZoneLookup.swift +++ b/Sources/SwiftTimeZoneLookup/SwiftTimeZoneLookup.swift @@ -25,7 +25,17 @@ public final class SwiftTimeZoneLookup { private let database16: OpaquePointer /// Throws if the timezone database could not be opened - public init() throws { + /// If an optional `databasePath` is provided, it tries first to uses this path and then uses the default bundle resources path + public init(databasePath: String? = nil) throws { + if let databasePath = databasePath, + let database21 = ZDOpenDatabase("\(databasePath)timezone21.bin"), + let database16 = ZDOpenDatabase("\(databasePath)timezone16.bin") + { + self.database21 = database21 + self.database16 = database16 + return + } + guard let timezone21 = Bundle.module.path(forResource: "timezone21", ofType: "bin") else { throw SwiftTimeZoneLookupError.couldNotFindTimezone21bin }