-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Datepicker choose day and timezone offset #5752
Comments
The problem is solved |
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? |
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. |
ng-model-options="{timezone:'UTC/GMT'}" |
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
Version of Angular, UIBS, and Bootstrap
Angular: 1.5.2
UIBS: 1.3.1
Bootstrap: 3.3.5
The text was updated successfully, but these errors were encountered: