github vapor/vapor 4.34.1
Honor Configuration for Optional Date Decoding & Encoding

latest releases: 4.95.0, 4.94.1, 4.94.0...
3 years ago
This patch was authored by @andtie and released by @0xTim.

Honor the configuration for Date Decoding & Encoding in URLEncodedFormDecoder / URLEncodedFormEncoder (fixes #2518).

// Configure a non-default date decoding strategy
let decoder = URLEncodedFormDecoder(configuration: .init(dateDecodingStrategy: .iso8601))
ContentConfiguration.global.use(urlDecoder: decoder)

// allow to use optional date-parameters in a request 
let after = try req.query.get(Date?.self, at: "after") ?? .distantPast

// => dates with the expected format (e.g. "...?after=2020-10-28T10:31:14Z") are correctly parsed

Don't miss a new vapor release

NewReleases is sending notifications on new releases.