ringsaturn/tzf-swift
> [!NOTE]
Usage
Add the dependency to your Package.swift file:
dependencies: [
.package(url: "https://github.com/ringsaturn/tzf-swift.git", from: "{latest_version}")
]Then add something like this:
import Foundation
import tzf
let finder = try DefaultFinder()
let timezone = try finder.getTimezone(lng: 116.3833, lat: 39.9167)
print("Beijing timezone:", timezone)
let timezones = try finder.getTimezones(lng: 87.5703, lat: 43.8146)
print("Multiple possible timezones:", timezones)
print("Data version:", finder.dataVersion())
if let macauGeoJSON = finder.getTimezoneGeoJSON(timezoneName: "Asia/Macau") {
print("Asia/Macau features:", macauGeoJSON.features.count)
print(try macauGeoJSON.toJSONString(pretty: false))
}Output:
Beijing timezone: Asia/Shanghai
Multiple possible timezones: ["Asia/Shanghai", "Asia/Urumqi"]
Data version: 2026a/2026a
Asia/Macau features: 1
{"type":"FeatureCollection","features":[{"geometry":{"type":"MultiPolygon","coor...Performance
Just like tzf packages in Go/Rust/Python, the Swift version is also fast, and designed for server-side high-performance use cases.
Hardware: MacBook Pro with Apple M3 Max.
Processing 1 million queries took 4500ms. Benchmark Summary:
| Implementation | Test Scale | Execution Time (ms) | Success Rate | Operations per Second (op/sec) | Memory Usage (Peak MB) | Instructions (G) | | ---------------------------- | ---------- | ------------------- | ------------ | ------------------------------ | ---------------------- | ---------------- | | TZF.DefaultFinder | 1,000,000 | 4,717 | 100% | ~212,000 | 129 | 73 | | TZF.Finder | 1,000,000 | 19,000 | 100% | ~52,632 | 115 | 324 | | TZF.PreindexFinder | 1,000,000 | 1,548 | ~85% | ~646,000 | 129 | 23 | | SwiftTimeZoneLookup.lookup | 10,000 | 3,077 | 100% | ~3,250 | 105 | 42 | | SwiftTimeZoneLookup.simple | 10,000 | 3,209 | 100% | ~3,116 | 104 | 45 |
Full benchmark results can be viewed in benchmark_baseline.txt.
Run Benchmarks
Benchmarks are isolated in the Benchmarks subpackage so the main package stays compatible with Swift 6.0 while benchmark tooling can use newer SwiftPM features.
make bench
# or:
cd Benchmarks && swift package benchmark --target TimezoneFinderBenchmarksLicense
This project is licensed under the MIT License. See the LICENSE file for details.
The data is licensed under ODbL-1.0 license, which compiled from <https://github.com/evansiroky/timezone-boundary-builder>
[[FOSSA Status]](https://app.fossa.com/projects/git%2Bgithub.com%2Fringsaturn%2Ftzf-swift?ref=badge_large)
Package Metadata
Repository: ringsaturn/tzf-swift
Default branch: main
README: README.md