SwiftTimeZoneLookup

1.0.7

Find timezones or countries for given coordinates
patrick-zippenfenig/SwiftTimeZoneLookup

What's New

Fix timezones in South America

2024-01-12T18:48:25Z

Full Changelog: 1.0.6...1.0.7

SwiftTimeZoneLookup

Test

Resolve geographical coordinates to timezones and countries. This is a Swift wrapper for ZoneDetect.

A timezone database with up to 20 meter resolution is embedded as a bundle resource (~5 MB). If you want to manually specify the database location, use try SwiftTimeZoneLookup(databasePath: "/path_to_timezone16_21_files/..")

Embedded timezone database version 2023d (2023-12-29).

This library is thread safe.

Usage

Add SwiftTimeZoneLookup as a dependency to your Package.swift

  dependencies: [
    .package(url: "https://github.com/patrick-zippenfenig/SwiftTimeZoneLookup.git", from: "1.0.0")
  ],
  targets: [
    .target(name: "MyApp", dependencies: [
      .product(name: "SwiftTimeZoneLookup", package: "SwiftTimeZoneLookup"),
    ])
  ]

In your code

import SwiftTimeZoneLookup


let database = try SwiftTimeZoneLookup()
guard let timezone = database.simple(latitude: 47.5, longitude: 8.6) else {
  fatalError("Timezone not found, coordinates invalid?")
}
print(timezone) // "Europe/Zurich"


guard let lookup = database.lookup(latitude: 47.5, longitude: 8.6) else {
  fatalError("Timezone not found, coordinates invalid?")
}
print(lookup) // SwiftTimeZoneLookupResult(timezone: "Europe/Zurich", countryName: Optional("Switzerland"), countryAlpha2: Optional("CH"))

Build database

SwiftTimeZoneLookup comes with an integrated database. The database can be updated with the following commands:

git clone --recurse-submodules git@github.com:patrick-zippenfenig/SwiftTimeZoneLookup.git

brew install shapelib wget
cd Submodules/ZoneDetect/database/builder

# make sure to select to newest version in make.db script

LIBRARY_PATH=/opt/homebrew/Cellar/shapelib/1.5.0/lib CPATH=/opt/homebrew/Cellar/shapelib/1.5.0/include ./makedb.sh

cp out_v1/timezone* ../../../../Sources/SwiftTimeZoneLookup/Resources

Credits

ZoneDetect as the upstream library.

Contains data from Natural Earth, placed in the Public Domain. Contains information from https://github.com/evansiroky/timezone-boundary-builder, which is made available here under the Open Database License (ODbL)

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Nov 22 2024 17:07:01 GMT-1000 (Hawaii-Aleutian Standard Time)