Skip to content

Commit

Permalink
Fix crash by using default hashing and equality for the config
Browse files Browse the repository at this point in the history
  • Loading branch information
ifosli committed Sep 6, 2023
1 parent de2ae46 commit 924181b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
21 changes: 1 addition & 20 deletions Library/Format.swift
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public enum Format {

public let defaultThresholdInDays = 30 // days

internal struct DateFormatterConfig {
internal struct DateFormatterConfig: Hashable {
let dateFormat: String?
fileprivate let dateStyle: DateFormatter.Style?
fileprivate let locale: Locale
Expand Down Expand Up @@ -439,25 +439,6 @@ internal struct DateFormatterConfig {
}
}

extension DateFormatterConfig: Hashable {
func hash(into hasher: inout Hasher) {
hasher.combine(self.template)
hasher.combine(self.dateStyle)
hasher.combine(self.locale)
hasher.combine(self.timeStyle)
hasher.combine(self.timeZone)
}
}

func == (lhs: DateFormatterConfig, rhs: DateFormatterConfig) -> Bool {
return
lhs.template == rhs.template
&& lhs.dateStyle == rhs.dateStyle
&& lhs.locale == rhs.locale
&& lhs.timeStyle == rhs.timeStyle
&& lhs.timeZone == rhs.timeZone
}

private struct NumberFormatterConfig {
fileprivate let numberStyle: NumberFormatter.Style
fileprivate let roundingMode: NumberFormatter.RoundingMode
Expand Down
6 changes: 6 additions & 0 deletions Library/FormatTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,12 @@ final class FormatTests: TestCase {
let date = Format.date(from: dateString, dateFormat: format, timeZone: PST)
XCTAssertEqual(date?.description, "2018-01-01 08:00:00 +0000")
}

// Test different format
withEnvironment(calendar: calEST) {
let date = Format.date(from: "2018-01-14", dateFormat: "yyyy-MM-dd")
XCTAssertEqual(date?.description, "2018-01-14 05:00:00 +0000")
}
}

func testDuration() {
Expand Down

0 comments on commit 924181b

Please sign in to comment.