diff --git a/Package.swift b/Package.swift index 0d1a517..a7083af 100644 --- a/Package.swift +++ b/Package.swift @@ -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") ], diff --git a/README.md b/README.md index 7001996..5397b86 100644 --- a/README.md +++ b/README.md @@ -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") ``` diff --git a/Sources/TypedDate/TypedDate+Hashable.swift b/Sources/TypedDate/TypedDate+Hashable.swift new file mode 100644 index 0000000..a9ae337 --- /dev/null +++ b/Sources/TypedDate/TypedDate+Hashable.swift @@ -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) + } + } +}