Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ability to Define a Date Format for URLEncodedFormEncoder and URLEncodedFormDecoder #2272

Closed
thecheatah opened this issue Mar 29, 2020 · 4 comments
Labels
enhancement New feature or request
Projects

Comments

@thecheatah
Copy link
Contributor

thecheatah commented Mar 29, 2020

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):

  • 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 formats
        public enum DateFormat {
            /// Seconds since 1 January 1970 00:00:00 UTC
            case unixTimestamp
            /// ISO 8601 formatted date
            case iso8601
            /// Using custom callback
            case 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 formats
        public enum DateFormat {
            /// Seconds since 1 January 1970 00:00:00 UTC
            case unixTimestamp
            /// ISO 8601 formatted date
            case iso8601
            /// Using custom callback
            case custom((Date, Encoder) throws -> Void)
        }

Actual behavior

No ability to override date formatting.

Environment

  • Vapor Framework version: 4
  • Vapor Toolbox version:
  • OS version: Linux
@thecheatah 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
@Joannis
Copy link
Member

Joannis commented Mar 30, 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.

@thecheatah
Copy link
Contributor Author

@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

@thecheatah
Copy link
Contributor Author

Default to timeIntervalSinceReferenceDate

@tanner0101 tanner0101 added the enhancement New feature or request label Mar 30, 2020
@tanner0101 tanner0101 added this to To Do in Vapor 4 via automation Mar 30, 2020
@tanner0101
Copy link
Member

Duplicate of #2133

@tanner0101 tanner0101 marked this as a duplicate of #2133 Apr 2, 2020
Vapor 4 automation moved this from To Do to Done Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Vapor 4
  
Done
Development

No branches or pull requests

3 participants