A type-safe Swift wrapper for IANA timezone identifiers and an extension for Foundation TimeZone identifiers.
- Type-safe IANA timezone identifiers
- Auto-generated from the latest IANA Time Zone Database
- Seamless integration with Foundation.TimeZone
- Support for all major Apple platforms (iOS, macOS, watchOS, tvOS, visionOS)
Add SwiftTZ to your Package.swift file:
dependencies: [
.package(url: "https://github.com/vamsii777/SwiftTZ.git", from: "0.2.0")
]To use a timezone, create a TimeZone instance using a TimeZoneIdentifier:
import SwiftTZ
let newYork = TimeZone(.americaNewYork)
print(newYork.identifier) // "America/New_York"The TimeZone initializer that takes a TimeZoneIdentifier will never fail because the set of identifiers is statically known and known to be valid.
let newYork = TimeZone(.americaNewYork)
print(newYork.identifier) // "America/New_York"let tokyo = TimeZone(identifier: .asiaTokyo)
print(tokyo.identifier) // "Asia/Tokyo"let london = TimeZone(.europeLondon) // "Europe/London"
let identifier = london.timeZoneIdentifier
print(identifier) // "europeLondon"Sources/SwiftTZ: The main librarySources/SwiftTZGenerator: The generator executable that fetches the latest IANA Time Zone DatabaseTests/SwiftTZTests: Unit tests
Contributions are welcome! If you encounter a bug or have a feature request, feel free to open an issue or submit a pull request.
- Clone the repository
git clone https://github.com/vamsi777/SwiftTZ.git
cd SwiftTZ- Run the generator to fetch the latest IANA Time Zone Database and generate the
TimeZoneIdentifier.swiftfile
swift run SwiftTZGeneratorSwiftTZ is licensed under the MIT license. See the LICENSE file for details.