Skip to content

Commit

Permalink
Merge pull request #2 from Ryu0118/feature/hashable
Browse files Browse the repository at this point in the history
Conformance to Hashable
  • Loading branch information
Ryu0118 authored Nov 13, 2023
2 parents d9b40f6 + ab16a23 commit d79d804
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let package = Package(
],
dependencies: [
// Depend on the Swift 5.9 release of SwiftSyntax
.package(url: "https://github.com/apple/swift-syntax.git", "508.0.0"..<"510.0.0"),
.package(url: "https://github.com/apple/swift-syntax.git", "509.0.0"..<"510.0.0"),
.package(url: "https://github.com/apple/swift-testing.git", from: "0.1.0"),
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.2.1")
],
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,5 @@ The Codable conformance means that TypedDate instances can be easily encoded to

## Installation
```Swift
.package(url: "https://github.com/Ryu0118/swift-typed-date", exact: "0.2.0")
.package(url: "https://github.com/Ryu0118/swift-typed-date", exact: "0.3.0")
```
31 changes: 31 additions & 0 deletions Sources/TypedDate/TypedDate+Hashable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Foundation

extension TypedDate: Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(date)
switch Components.self {
case is (Year).Type:
hasher.combine(1)

case is (Year, Month).Type:
hasher.combine(2)

case is (Year, Month, Day).Type:
hasher.combine(3)

case is (Year, Month, Day, Hour).Type:
hasher.combine(4)

case is (Year, Month, Day, Hour, Minute).Type:
hasher.combine(5)

case is (Year, Month, Day, Hour, Minute, Second).Type:
hasher.combine(6)

case is (Year, Month, Day, Hour, Minute, Second, Nanosecond).Type:
hasher.combine(6)

default: hasher.combine(7)
}
}
}

0 comments on commit d79d804

Please sign in to comment.