angular-ui / bootstrap

PLEASE READ THE PROJECT STATUS BELOW. Native AngularJS (Angular) directives for Bootstrap. Smaller footprint (20kB gzipped), no 3rd party JS dependencies (jQuery, bootstrap JS) required. Please read the README.md file before submitting an issue!
http://angular-ui.github.io/bootstrap/
MIT License
14.29k stars 6.73k forks source link

Datepicker ignores time when model becomes null #5744

Open guinnberg opened 8 years ago

guinnberg commented 8 years ago

Bug description:

If either the model is null or it's set to null, the parser ignores the time which is causing issues after the summer time change (GMT+1 specially, setting the date to the previous day at 23:00)

Link to minimally-working plunker that reproduces the issue:

http://plnkr.co/edit/Mc2JbTXm4GYNA5wX8pC7?p=preview As is shown at the beginning, the date is parsed to UTC with time (as spected), but if you click on clear button and then select another date, the time is ignored.

Version of Angular, UIBS, and Bootstrap

Angular: 1.5.3

UIBS: 1.3.0

Bootstrap: 3.3.6

wesleycho commented 8 years ago

I'm confused - is the Plunker wrong? I don't see a clear button.

guinnberg commented 8 years ago

I edited the url of the plunker, now you should see it

wesleycho commented 8 years ago

I'm still a bit confused - how is the time being set to UTC? I don't see any particular timezone specific code here. The initial timezone of the date seems weird - I actually would expect the subsequent behavior on setting of the date based on the code I am seeing. Can you point out what I am missing here?

guinnberg commented 8 years ago

Sorry, maybe I didn't explain properly.

When I'm mentioning UTC is because it's the default parsing being done by angular, following the ISO format which says: Times are expressed in UTC (Coordinated Universal Time), with a special UTC designator ("Z")

To reproduce the issue take the following steps:

  1. Click on 'Clear' button
  2. Click on 20th of April for example

Expected result: "2016-04-20T14:01:25.817Z" (Assuming I ran it at 3pm UTC+1) or at least "2016-04-20T00:00:00.000Z" Actual result: "2016-04-19T23:00:00.000Z"

My other explanations were to point out that this doesn't happen if you provide a default date with time (it'll keep the time).

I hope is clearer now.

wesleycho commented 8 years ago

In that case, you should explicitly use ng-model-options="{timezone: 'utc'}" - changing that in the library could be a badly breaking change.

guinnberg commented 8 years ago

That definitely fix the problem, but isn't it inconsistent to take in count the time of the date object when provided and have it reset to 0:00:00 when isn't?

Looks like there is a similar problem in this other open issue: https://github.com/angular-ui/bootstrap/issues/5759

wesleycho commented 8 years ago

So how the datepicker operates with timezones is it bases the dates for the objects representing each day/month/year in the calendar off of the date of the active date - if that date switches to null, then we lose the information and have no safe assumption as to what it should be next.