Custom Date Value Wrapper
umairsuraj opened this issue · 2 comments
umairsuraj commented
Is there any option for decoding entities that have custom date formats?
marksands commented
Yes, definitely possible. Make a type that conforms to DateValueCodableStrategy
(see https://github.com/marksands/BetterCodable/blob/master/Sources/BetterCodable/DateValue.swift#L6-L11) And use it like so:
struct Response: Codable {
@DateValue<SomeCustomDateFormatterStrategy> var someDate: Date
@DateValue<OtherCustomDateFormatterStrategy> var otherDate: Date
}
For inspiration, take a look at YearMonthDayStrategy and RFC2822Strategy.
alexj70 commented
Hi. Is it possible to use optional value for the date property?