vamsii777/swifttz
A type-safe Swift wrapper for IANA timezone identifiers and an extension for Foundation `TimeZone` identifiers.
Getting Started
Add SwiftTZ to your Package.swift file:
dependencies: [
.package(url: "https://github.com/vamsii777/SwiftTZ.git", from: "0.2.0")
]Usage
To use a timezone, create a TimeZone instance using a TimeZoneIdentifier:
import SwiftTZ
let newYork = TimeZone(.americaNewYork)
print(newYork.identifier) // "America/New_York"TimeZone Initialization
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"Package Structure
Sources/SwiftTZ: The main librarySources/SwiftTZGenerator: The generator executable that fetches the latest IANA Time Zone DatabaseTests/SwiftTZTests: Unit tests
Contributing
Contributions are welcome! If you encounter a bug or have a feature request, feel free to open an issue or submit a pull request.
Setting Up
- 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 SwiftTZGeneratorAcknowledgments
License
SwiftTZ is licensed under the MIT license. See the LICENSE file for details.
Package Metadata
Repository: vamsii777/swifttz
Default branch: main
README: README.md