Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conformance to Hashable #2

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
}