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

Custom date coding for URLEncodedForm #2133

Closed
tonyarnold opened this issue Dec 19, 2019 · 3 comments
Closed

Custom date coding for URLEncodedForm #2133

tonyarnold opened this issue Dec 19, 2019 · 3 comments
Labels
enhancement New feature or request
Projects

Comments

@tonyarnold
Copy link
Contributor

I had a use-case today where my front-end HTML form was posting a UNIX timestamp to a Vapor route where I wanted to decode that value to a Date.

Unfortunately, it seems like URLEncodedFormDecoder is utilising Date(timeIntervalSinceReferenceDate:) rather than the correct (in this instance) Date(timeIntervalSince1970:), so all of my decoded dates were about 30 years off.

Steps to reproduce

  1. Create a simple model with a Date property:
    struct MyModel: Content {
          let expiryDate: Date
    }
  2. Create a that accepts this model via a post (router.post(MyModel.self, at: …))
  3. Create a simple HTML form that posts to this route with a single value: expiryDate
  4. Submit a UNIX timestamp via this form, and observe the date that gets decoded onto the model instance in your route handler.

Expected behavior

The date is decoded as a common UNIX epoch timestamp (00:00:00 UTC on 1 January 1970).

If this can't be determined automatically, then I'd expect to be able to override or customise this decoding much like we can with JSONDecoder.DataDecodingStrategy.

Actual behavior

The date is decoded using Foundation's reference date (00:00:00 UTC on 1 January 2001).

Environment

  • Vapor Framework version: 3.3.1
  • Vapor Toolbox version: 3.1.10
  • OS version: macOS 10.15.2
@tanner0101 tanner0101 added the enhancement New feature or request label Apr 2, 2020
@tanner0101 tanner0101 added this to To Do in Vapor 4 via automation Apr 2, 2020
@tanner0101
Copy link
Member

Related to #2273

@tanner0101 tanner0101 changed the title Support for customising the date decoding used by URLEncodedFormDecoder Custom date coding for URLEncodedForm Apr 2, 2020
@thecheatah
Copy link
Contributor

thecheatah commented Apr 2, 2020

The documentation for pull #2273 is here #2272

@Joannis
Copy link
Member

Joannis commented Aug 27, 2020

Closing this due to a fix having been merged.

@Joannis Joannis closed this as completed Aug 27, 2020
Vapor 4 automation moved this from To Do to Done Aug 27, 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

4 participants