New timezone - new problems

    Returning from a short vacation, I discovered that the admin set a new timezone RTZ 2. As a result, some browsers began to work somewhat strange with dates. Here is, for example, what December 2013 looks like in the jquery ui calendar (quite an old version):



    There is no doubt that it should be updated, but this is a corporate environment, and it's not so simple.
    It was useful to watch what was happening, and I saw strange things. Started with the simplest

      var date = new Date(2014,0,1)
    

    In IE8, this is not January 1, as one might think, but December 31, 2013! (check in older versions).
    But everyone has long been accustomed to the peculiar behavior of IE, and the screenshot shown above was shot in chrome, the results are the same.
    Well, what to do with the calendar? If you rummage through the source, the reason for the specified image is an incorrect determination of the number of days in a month. The code below for December in chrome and IE returns 1!
    return 32 - new Date(year, month, 32).getDate();
    

    So far, I replaced it with this, it seems, works:
    return new Date(year, month+1, 0).getDate();
    

    Setters also work incorrectly. For example, in both chrome and IE, the specified code gives amazing results:
    var date = new Date(2014,0,2);
    date.setDate(1);
    

    I haven’t found any troubles in opera and firefox yet. Also, in the latest version of jquery ui, December 2013 is displayed normally. However, now you have to check the scripts for availability on January 1, 2014.

    How do you deal with this problem?

    UPD
    Until patched browser versions are published, you can fix the calendar directly in jquery ui.
    - if the old version is used, then it is necessary to change the function for determining the number of days in a month:
        /* Find the number of days in a given month. */
        _getDaysInMonth: function(year, month) {
            return new Date(year, month+1, 0).getDate();
        },
    

    In addition, it is necessary to change the function of calculating the day of the week of the first day of the month, adding at least 1 hour to the date (4th argument):
        /* Find the day of the week of the first of a month. */
        _getFirstDayOfMonth: function(year, month) {
            return new Date(year, month, 1, 1).getDay();
        },
    

    Without this fix, January 2014 does not display correctly - as if it started on Tuesday.

    Also popular now: