From 55f3d6e384252d9c587f8736982c2af50d3828d3 Mon Sep 17 00:00:00 2001 From: patrick-zippenfenig Date: Mon, 20 Nov 2023 09:14:56 +0100 Subject: [PATCH] fix memory leak and invalid timezone for greek island --- Sources/SwiftTimeZoneLookup/SwiftTimeZoneLookup.swift | 8 ++++++++ .../SwiftTimeZoneLookupTests.swift | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/Sources/SwiftTimeZoneLookup/SwiftTimeZoneLookup.swift b/Sources/SwiftTimeZoneLookup/SwiftTimeZoneLookup.swift index b86e724..5c17744 100644 --- a/Sources/SwiftTimeZoneLookup/SwiftTimeZoneLookup.swift +++ b/Sources/SwiftTimeZoneLookup/SwiftTimeZoneLookup.swift @@ -63,6 +63,8 @@ public final class SwiftTimeZoneLookup { if safezone >= 0.0055*2 { return result } + ZDFreeResults(result) + guard let result21 = ZDLookup(database21, latitude, longitude, &safezone) else { return nil } @@ -108,6 +110,12 @@ public final class SwiftTimeZoneLookup { /// Resolve the timz public func simple(latitude: Float, longitude: Float) -> String? { + if (36.2443...36.7389).contains(latitude) && (26.0019...26.7957).contains(longitude) { + // Astypalaia island in Greece does not resolve any timezone and would return nil + // Reasons unknown, could be an invalid polygon + return "Europe/Athens" + } + guard let result = highResLookup(latitude: latitude, longitude: longitude) else { return nil } diff --git a/Tests/SwiftTimeZoneLookupTests/SwiftTimeZoneLookupTests.swift b/Tests/SwiftTimeZoneLookupTests/SwiftTimeZoneLookupTests.swift index 6e71fcf..68f98f9 100644 --- a/Tests/SwiftTimeZoneLookupTests/SwiftTimeZoneLookupTests.swift +++ b/Tests/SwiftTimeZoneLookupTests/SwiftTimeZoneLookupTests.swift @@ -17,5 +17,13 @@ final class SwiftTimeZoneLookupTests: XCTestCase { // on the border to the netherlands. Requires high resolution lookup XCTAssertEqual(database.simple(latitude: 53.242293, longitude: 7.209253), "Europe/Berlin") XCTAssertEqual(database.simple(latitude: 53.239692, longitude: 7.207879), "Europe/Amsterdam") + + // Astypalaia island in Greece does not resolve any timezone and would return nil + // Reasons unknown, could be an invalid polygon + XCTAssertEqual(database.simple(latitude: 36.5362, longitude: 26.3396), "Europe/Athens") // Hard coded fix now in code + XCTAssertEqual(database.simple(latitude: 36.8370, longitude: 25.8904), "Europe/Athens") // island to the north + XCTAssertEqual(database.simple(latitude: 36.3683, longitude: 25.7735), "Europe/Athens") // island to north west + + } }