mirror of
https://github.com/samsonjs/SwiftTimeZoneLookup.git
synced 2026-03-25 08:25:49 +00:00
error handling
This commit is contained in:
parent
f58408cb4e
commit
025a4e71a7
2 changed files with 4 additions and 6 deletions
|
|
@ -13,21 +13,17 @@ public final class SwiftTimeZoneLookup {
|
|||
guard let timezone21 = Bundle.module.url(forResource: "timezone21", withExtension: "bin") else {
|
||||
throw SwiftTimeZoneLookupError.couldNotFindTimezone21bin
|
||||
}
|
||||
|
||||
guard let database = timezone21.withUnsafeFileSystemRepresentation({ timezone21 in
|
||||
ZDOpenDatabase(timezone21)
|
||||
}) else {
|
||||
throw SwiftTimeZoneLookupError.couldNotOpenDatabase
|
||||
}
|
||||
self.database = database
|
||||
|
||||
|
||||
print(timezone21)
|
||||
}
|
||||
|
||||
public func lookup(latitude: Float, longitude: Float) -> String {
|
||||
public func lookup(latitude: Float, longitude: Float) -> String? {
|
||||
guard let cTimezone = ZDHelperSimpleLookupString(database, latitude, longitude) else {
|
||||
fatalError()
|
||||
return nil
|
||||
}
|
||||
let timezone = String(cString: cTimezone)
|
||||
ZDHelperSimpleLookupStringFree(cTimezone)
|
||||
|
|
|
|||
|
|
@ -8,5 +8,7 @@ final class SwiftTimeZoneLookupTests: XCTestCase {
|
|||
XCTAssertEqual(database.lookup(latitude: 47.5, longitude: -2.6), "Europe/Paris")
|
||||
XCTAssertEqual(database.lookup(latitude: 47.5, longitude: -8.6), "Etc/GMT+1")
|
||||
XCTAssertEqual(database.lookup(latitude: 42.5, longitude: -8.6), "Europe/Madrid")
|
||||
|
||||
XCTAssertEqual(database.lookup(latitude: 242.5, longitude: -8.6), nil)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue