Skip to content

Conversation

@mernen
Copy link
Contributor

@mernen mernen commented Aug 24, 2017

The current implementation of Date serialization 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 a getUTCHours() 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.

BREAKING CHANGE: this affects the server-side parsing of dates sent by
this library. Previously, the server had to completely ignore the
timezone information ("UTC"), then treat the date as local. Now the
front-end will properly send the local date plus the local timezone,
which allows the back-end to reliably choose between either handling it
as a local time, or convert it to some other timezone, like UTC.
@coveralls
Copy link

coveralls commented Aug 24, 2017

Coverage Status

Coverage remained the same at 83.52% when pulling 844c8c4 on mernen:fix-date-timezone into 00af920 on ghidoz:master.

@HennerM HennerM added this to the v4.0.0 milestone Aug 25, 2017
@HennerM HennerM merged commit 844c8c4 into ghidoz:master Dec 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants