marksands/BetterCodable

Custom Date Value Wrapper

umairsuraj opened this issue · 2 comments

Is there any option for decoding entities that have custom date formats?

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.

Hi. Is it possible to use optional value for the date property?