Skip to content

Commit

Permalink
Fix boolean to enum case conversion for relativeToReferenceDate
Browse files Browse the repository at this point in the history
  • Loading branch information
Joannis committed Apr 21, 2024
1 parent cac4baa commit 6dbde5e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Sources/BSON/Codable/Decoding/BSONDecoderSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,18 @@ public struct BSONDecoderSettings {
/// If `true`, allows decoding Date from a Double (TimeInterval)
public var decodeDateFromTimestamp: Bool {
get { timestampToDateDecodingStrategy != .never }
set { timestampToDateDecodingStrategy = newValue ? .relativeToUnixEpoch : .never }
set(decodeDateFromTimestamp) {
switch timestampToDateDecodingStrategy {
case .never:
if decodeDateFromTimestamp {
timestampToDateDecodingStrategy = .relativeToUnixEpoch
}
case .relativeToReferenceDate, .relativeToUnixEpoch:
if !decodeDateFromTimestamp {
timestampToDateDecodingStrategy = .never
}
}
}
}

/// A strategy to apply when converting time interval to date objects
Expand Down

0 comments on commit 6dbde5e

Please sign in to comment.