Skip to content

Type-safe TimeZone identifiers for Swift, powered by pkl.

License

Notifications You must be signed in to change notification settings

vamsii777/SwiftTZ

Repository files navigation

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:

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 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
git clone https://github.com/vamsi777/SwiftTZ.git
cd SwiftTZ
  1. Run the generator to fetch the latest IANA Time Zone Database and generate the TimeZoneIdentifier.swift file
swift run SwiftTZGenerator

Acknowledgments

License

SwiftTZ is licensed under the MIT license. See the LICENSE file for details.