Fix timezone in serialized dates #90
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current implementation of
Dateserialization sends the current local date with a hardcoded "Z" prefix, completely discarding timezone information.Example
For example, let’s say the user is located at UTC-4, and they choose 10 am Aug 24 on some timepicker. This is what this library currently sends to the server:
2017-08-24T10:00:00Z.If the backend is written in, say, Node.js, calling
getHours()would return 6 rather than the expected 10. To work around this, it must either use agetUTCHours()call, or discard the “Z” suffix and assume the time is local (but then they don’t know the client’s timezone and can’t convert it to actual UTC if needed).With this patch, the frontend will instead send:
2017-08-24T10:00:00-04:00. The backend is then free to choose between working with local time or UTC, as both will return the expected values.Breaking change
However, it's possible there are servers already designed around the current behavior, so this means this fix is technically a breaking change. I'd recommend holding it off until a planned 4.0 release.