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

Handling birthday - timezone issues #282

Open
csimpi opened this issue Jan 21, 2019 · 1 comment
Open

Handling birthday - timezone issues #282

csimpi opened this issue Jan 21, 2019 · 1 comment

Comments

@csimpi
Copy link

csimpi commented Jan 21, 2019

Hi, I have an issue with the timezones and I can't find the solution.
When the user picks his/her birthday's date the angular-moment-picker is automatically converting the date to UTC format. This is not too lucky since when I'm sending the picked date to the backend the UTC date will be sent so I don't know what was the local timezone of the client.
For example, if I'm in GMT and select my birthday: 1980-01-21 the backend will get 1980-01-20 as a date, and the wrong birthday will be stored (01-20 instead 01-21).
When the users want to see other user's birthday a wrong date appears when a user is in different timezone from GMT, only those users are getting the correct value (01-21) who are in the same timezone like me (GMT), users with a browser in UTC will get the wrong 01-20 birthday date.

I have no idea how to handle this on the backend side ( I don't want to convert back and forth the picked date object on the client side that would be a bit ugly).

Can I somehow avoid converting the picked value to UTC automatically? Or any other suggestions how should I handle this?

@CJDennis
Copy link

The trick is to manually convert the moment object to UTC while not changing the display time:

var m = moment();
var keepLocalTime = true;

m.utc(keepLocalTime);

Now the value sent back to the back-end will still be in UTC (the default), but on the correct date.

For the issue of displaying values sent by the server, you might need to use m.local(keepLocalTime).

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

No branches or pull requests

2 participants