https://github.com/vamsii777/swifttz
Type-safe TimeZone identifiers for Swift, powered by pkl.
https://github.com/vamsii777/swifttz
pkl swift swift-library timezone
Last synced: 12 days ago
JSON representation
Type-safe TimeZone identifiers for Swift, powered by pkl.
- Host: GitHub
- URL: https://github.com/vamsii777/swifttz
- Owner: vamsii777
- License: mit
- Created: 2024-11-21T13:47:34.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-11-28T07:13:45.000Z (6 months ago)
- Last Synced: 2025-05-08T07:52:37.566Z (12 days ago)
- Topics: pkl, swift, swift-library, timezone
- Language: Swift
- Homepage:
- Size: 1.76 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# SwiftTZ
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)## Getting Started
Add SwiftTZ to your `Package.swift` file:
```swift
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`:
```swift
import SwiftTZlet 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.
```swift
let newYork = TimeZone(.americaNewYork)
print(newYork.identifier) // "America/New_York"
``````swift
let tokyo = TimeZone(identifier: .asiaTokyo)
print(tokyo.identifier) // "Asia/Tokyo"
``````swift
let london = TimeZone(.europeLondon) // "Europe/London"
let identifier = london.timeZoneIdentifier
print(identifier) // "europeLondon"
```## Package Structure
- `Sources/SwiftTZ`: The main library
- `Sources/SwiftTZGenerator`: The generator executable that fetches the latest IANA Time Zone Database
- `Tests/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
1. Clone the repository
```sh
git clone https://github.com/vamsi777/SwiftTZ.git
cd SwiftTZ
```2. Run the generator to fetch the latest IANA Time Zone Database and generate the `TimeZoneIdentifier.swift` file
```sh
swift run SwiftTZGenerator
```## Acknowledgments
- [IANA Time Zone Database](https://www.iana.org/time-zones)
- [PklSwift](https://github.com/apple/pkl-swift)
- [eggert/tz](https://github.com/eggert/tz)## License
SwiftTZ is licensed under the MIT license. See the [LICENSE](LICENSE) file for details.