Skip to content

Commit

Permalink
Fix test suite and improve documentation (#3)
Browse files Browse the repository at this point in the history
* Fix tests and update timezone identifier format in documentation

- Fix americaNew_York to americaNewYork in code examples
- Update generated file name from TimeZoneModule.pkl.swift to TimeZoneIdentifier.swift
- Maintain consistent identifier formatting throughout README
  • Loading branch information
vamsii777 authored Nov 21, 2024
1 parent 0d83be2 commit 5291bc0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/Packages
xcuserdata/
DerivedData/
.swiftpm/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Add SwiftTZ to your `Package.swift` file:

```swift
dependencies: [
.package(url: "https://github.com/vamsi777/SwiftTZ.git", from: "0.1.0")
.package(url: "https://github.com/vamsi777/SwiftTZ.git", from: "0.2.0")
]
```

Expand All @@ -24,7 +24,7 @@ To use a timezone, create a `TimeZone` instance using a `TimeZoneIdentifier`:
```swift
import SwiftTZ

let newYork = TimeZone(.americaNew_York)
let newYork = TimeZone(.americaNewYork)
print(newYork.identifier) // "America/New_York"
```

Expand All @@ -33,7 +33,7 @@ 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.

```swift
let newYork = TimeZone(.americaNew_York)
let newYork = TimeZone(.americaNewYork)
print(newYork.identifier) // "America/New_York"
```

Expand Down Expand Up @@ -66,7 +66,7 @@ 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 `TimeZoneModule.pkl.swift` file
2. Run the generator to fetch the latest IANA Time Zone Database and generate the `TimeZoneIdentifier.swift` file

```sh
swift run tzdb-gen
Expand Down
12 changes: 6 additions & 6 deletions Tests/SwiftTZTests/TimeZoneTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import Testing
struct TimeZoneTests {
@Test func timeZoneCreation() {
// Test valid timezone creation
#expect(throws: Never.self) { TimeZone(identifier: .americaNew_York) }
#expect(throws: Never.self) { TimeZone(identifier: .americaNewYork) }
#expect(throws: Never.self) { TimeZone(.europeLondon) }
#expect(throws: Never.self) { TimeZone(.asiaTokyo) }

// Test timezone properties
let nyTz = TimeZone(.americaNew_York)
#expect(nyTz.timeZoneIdentifier == .americaNew_York)
let nyTz = TimeZone(.americaNewYork)
#expect(nyTz.timeZoneIdentifier == .americaNewYork)
#expect(nyTz.identifier == "America/New_York")
}

@Test func commonTimeZones() {
// Test some commonly used timezones
let timezones: [TimeZoneIdentifier] = [
.europeLondon, // UTC+0/+1
.americaNew_York, // UTC-5/-4
.americaNewYork, // UTC-5/-4
.asiaTokyo, // UTC+9
.australiaSydney, // UTC+10/+11
.pacificHonolulu, // UTC-10
Expand All @@ -34,7 +34,7 @@ struct TimeZoneTests {

@Test func timeZoneRoundTrip() {
// Test that converting from Foundation.TimeZone to our identifier and back works
let originalTz = TimeZone(.americaNew_York)
let originalTz = TimeZone(.americaNewYork)
let identifier = originalTz.timeZoneIdentifier
let roundTripTz = TimeZone(identifier)

Expand All @@ -52,7 +52,7 @@ struct TimeZoneTests {

@Test func timeZoneOffsets() {
// Test timezone offset calculations
let nyTz = TimeZone(.americaNew_York)
let nyTz = TimeZone(.americaNewYork)
let tokyoTz = TimeZone(.asiaTokyo)

// Create dates using Calendar to ensure proper date creation
Expand Down

0 comments on commit 5291bc0

Please sign in to comment.