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

Dateparser does not always maintain timezone of baseDate #6441

Open tflavin opened 7 years ago

tflavin commented 7 years ago

Bug description:

The documentation for uibDateParser's parse function contains this description of baseDate:

However, the uibDateParser's parse function will not always maintain the timezone.

If my local timezone is set to automatically adjust for Daylight Savings Time (via system setting), the dateParser will also adjust the timezone for Daylight Savings Time if the input date falls within the the DST date range. This means that the date returned will sometimes be either the previous or following date.

This seems to be happening when the dateParser calls JavaScript's Date.prototype's functions getHours(), getMinutes(), getSeconds(), and getMilliseconds() - since these take the user's local time into account - instead of using the UTC versions getUTCHours(), getUTCMinutes(), getUTCSeconds(), and getUTCMilliseconds().

I noticed this when I created a baseDate that represents -0500 UTC, which is the timezone I wish to maintain and passed a 'yyyy-MM-dd' input string to the dateParser. Depending on the input string and the local timezone settings, the Date that dateParser returned may or may not have the -0500 UTC timezone.

Ex run where local timezone set to EST (dates then formatted for display using Angular's date filter with '-0500' timezone):

Link to minimally-working plunker that reproduces the issue:

https://plnkr.co/edit/peEkk04I992trGszaEIE?p=preview Make sure your local date is set to EST, CST, MST, PST and your system is set to automatically adjust for DST. I have included example dates near the start and end of Daylight Savings to highlight the fact that is inconsistently parsing in this case. The date that show this depend on your local timezone, so you can select them at the top. I have also included examples showing that JavaScript's Date.prototype's UTC methods seem to consistently work.

Version of Angular, UIBS, and Bootstrap

Angular: 1.5.8

UIBS: 2.4.0

Bootstrap: 3.3.7