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
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
Create a simple model with a Date property:
structMyModel:Content{letexpiryDate:Date}
Create a that accepts this model via a post (router.post(MyModel.self, at: …))
Create a simple HTML form that posts to this route with a single value: expiryDate
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
The text was updated successfully, but these errors were encountered:
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 utilisingDate(timeIntervalSinceReferenceDate:)
rather than the correct (in this instance)Date(timeIntervalSince1970:)
, so all of my decoded dates were about 30 years off.Steps to reproduce
Date
property:router.post(MyModel.self, at: …)
)expiryDate
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
The text was updated successfully, but these errors were encountered: