fix memory leak and invalid timezone for greek island

This commit is contained in:
patrick-zippenfenig 2023-11-20 09:14:56 +01:00
parent b03b9853ce
commit 55f3d6e384
2 changed files with 16 additions and 0 deletions

View file

@ -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
}

View file

@ -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
}
}