You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the URL Coders code and decode to Unix Timestamp. I would like to be able to override code/decode to support ISO 8601 and custom date formats.
ISO 8601 Supports all of the following date formats (and more):
2020-03-29
2020-03-29T14:25:05+00:00
2020-03-29T14:25:05Z
Expected behavior
Modify URLEncodedFormDecoder.Configuration to take an array of enum values DateFormat where decoding will be tried with the date formats provided in the array. Defaults to decoding as Unix Timestamp and if that doesn't work ISO8601 ([.timeIntervalSince1970, .iso8601]).
Where URLEncodedFormDecoder.Configuration.DateFormat is
/// Supported date formatspublicenumDateFormat{/// Seconds since 1 January 1970 00:00:00 UTCcase unixTimestamp
/// ISO 8601 formatted datecase iso8601
/// Using custom callbackcase custom((Decoder)throws->Date)}
Modify URLEncodedFormEncoder.Configuration to take in enum value DateFormat. Defaults to Unix Timestamp (.unixTimestamp)
Where URLEncodedFormEncoder.Configuration.DateFormat is
/// Supported date formatspublicenumDateFormat{/// Seconds since 1 January 1970 00:00:00 UTCcase unixTimestamp
/// ISO 8601 formatted datecase iso8601
/// Using custom callbackcase custom((Date,Encoder)throws->Void)}
Actual behavior
No ability to override date formatting.
Environment
Vapor Framework version: 4
Vapor Toolbox version:
OS version: Linux
The text was updated successfully, but these errors were encountered:
thecheatah
changed the title
Add Ability to Define a Date Formatter for URLEncodedFormEncoder and URLEncodedFormDecoder
Add Ability to Define a Date Format for URLEncodedFormEncoder and URLEncodedFormDecoder
Mar 29, 2020
Can this be added post-release/without breaking API? I think so, in which case adding this with the current method as default would be preferred for me.
@Joannis Thanks for taking a look. We can default it to timeIntervalSinceReferenceDate, but it didn't make sense for it to be the default as it's Apple specific.
I have a feeling that not a lot of people have tried to Encode/Decode to date from the URLEncodedForm, otherwise someone would have raised it as a bug.
I can default it to timeIntervalSinceReferenceDate if considering the above, we are OK with defaulting date encoding/decoding to something non-standard. Vapor 4 implementations will go live expecting Apple's timeIntervalSinceReferenceDate
Created pull request #2273
Steps to reproduce
Currently, the URL Coders code and decode to Unix Timestamp. I would like to be able to override code/decode to support ISO 8601 and custom date formats.
ISO 8601 Supports all of the following date formats (and more):
Expected behavior
Modify URLEncodedFormDecoder.Configuration to take an array of enum values DateFormat where decoding will be tried with the date formats provided in the array. Defaults to decoding as Unix Timestamp and if that doesn't work ISO8601 (
[.timeIntervalSince1970, .iso8601]
).Where
URLEncodedFormDecoder.Configuration.DateFormat
isModify URLEncodedFormEncoder.Configuration to take in enum value DateFormat. Defaults to Unix Timestamp (
.unixTimestamp
)Where
URLEncodedFormEncoder.Configuration.DateFormat
isActual behavior
No ability to override date formatting.
Environment
The text was updated successfully, but these errors were encountered: