Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Datepicker choose day and timezone offset #5752

Closed
isimonov opened this issue Apr 6, 2016 · 4 comments
Closed

Datepicker choose day and timezone offset #5752

isimonov opened this issue Apr 6, 2016 · 4 comments

Comments

@isimonov
Copy link

isimonov commented Apr 6, 2016

Bug description:

If Datepicker field empty and we choose a date, then creates a new date object with the given timezone offset (depends on locale), i.e. if I choose an empty field 2015-01-02, it turns out the date 2015-01-01 21:00:00 (if the timezone offset is +3 hours), i.e. yesterday, unless you consider time. This is not quite correct when sent to the server, if there is not taken into account the timezone offset or it works with UTC. Maybe there could be something to do?

If a server is using UTC (timezone offset is 0 hours), and the browser's local timezone (timezone offset is +3 hours) may occur such a situation: all dates are returned from the server is correct, for example 2015-01-02 00:00:00, and if the date entered for the first time the datepicker will create you same date as 2015-01-01 21:00:00 When I pass this 2 dstes on server, this is will be different dates from his point of view. It is very inconvenient to use, but it's a feature of Javascript works with dates in the browser.

My similarly issue: #4113

Then it was fixed...

Link to minimally-working plunker that reproduces the issue:

http://plnkr.co/edit/tfOyErmBZZICj1dFVNCI?p=preview

6f130852-4010-11e5-861e-9a36a53498b8

Version of Angular, UIBS, and Bootstrap

Angular: 1.5.2
UIBS: 1.3.1
Bootstrap: 3.3.5

@isimonov
Copy link
Author

isimonov commented Apr 6, 2016

The problem is solved
ngModelOptions={timezone:'UTC/GMT'}
Not understand right away...

@isimonov isimonov closed this as completed Apr 6, 2016
@JonCognioDigital
Copy link

Maybe I'm just confused here but is the problem not that when you pick a date (e.g. 15th May) and you are in a timezone that is not UTC (e.g. BST which is GMT+1) the datepicker is internally compensating for this and removing an hour before returning the value to the ng-model?

The solution seems to be to tell the datepicker what timezone you are in so it can compensate for this error when setting the ng-model value. So, you're taking an hour off and then putting it back on again. The trouble is that if I have a user in another timezone I would need to detect their timezone and look up the abbreviation so I can set it in ng-model-options. This is difficult and as far as I can see, a bit pointless.

Shouldn't the datepicker just set 00:00 UTC in the date and not remove an hour from it in the first place?

There may be a good reason that I don't understand, but this must be a very common problem, right?

@isimonov
Copy link
Author

The browser always creates an object date/time to the current time zone of the user. Unfortunately you cannot create a UTC (timezone offset is 0 hours) date/time in its purest form. Always have anyway to solve this problem itself. In our case ngModelOptions={timezone:'UTC/GMT'} does what we need.

@batmaster
Copy link

ng-model-options="{timezone:'UTC/GMT'}"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants