Praveen Kumar Thalluri Praveen Kumar Thalluri - 29 days ago 9
jQuery Question

jQuery UI Date Picker issue on IE9 and below. Shows wrong date in UTC +2 time zones


  • Use IE9 or below.

  • Change the time zone of the computer to UTC+2 -Amman.

  • Navigate to https://jqueryui.com/datepicker/

  • Click in the textbox to reveal date picker control.

  • Use the arrows to go to Apr/2016.

  • You can see the day of 01/Apr/2016 as Thursday which is INCORRECT.

  • Use IE10 or above, shows the day of 01/Apr/2016 as Friday which
    is CORRECT.



Any fix available for this bug?

Answer

jQuery date picker control relies on JS Date function to build the calendar. Apparently, JS date function reports wrong info in IE9 and below.

For example:
new Date(2016,3,1)
IE9 and below prints Thu Mar 31 23:00:00 UTC+0200 2016 - INCORRECT
IE10 and above prints Fri Apr 1 01:00:00 UTC+0300 2016[date] Fri Apr 1 01:00:00 UTC+0300 2016 - CORRECT

Possible Fix:
Edit the jQueryUI JS file and update the function _getFirstDayOfMonth as below.

_getFirstDayOfMonth: function (year, month) {
            // This code is needed as IE9 and below reports the wrong date value for UTC+2 timezones
            if(navigator.userAgent.indexOf("MSIE 9.0") > -1 || navigator.userAgent.indexOf("MSIE 8.0") > -1 || navigator.userAgent.indexOf("MSIE 7.0") > -1)
                return new Date( year, month, 1,23 ).getDay();
            else
                return new Date( year, month, 1 ).getDay();
        }