📜 ⬆️ ⬇️

New timezone - new problems

Returning from a short vacation, I discovered that the admin has installed a new time zone for RTZ 2. As a result, some browsers began to work with dates in a somewhat strange manner. Here, for example, looks like December 2013 in the jquery ui calendar (rather old version):



There is no doubt that it should be updated, but this is a corporate environment, and not everything is so simple.
Got to look what is happening, and 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 for higher versions).
But everybody got used to the peculiar behavior of IE for a long time, and the screenshot shown above was taken in chrome, the same results.
Well, and what to do with the calendar? If you rummage in the source, the reason for this picture is the incorrect determination of the number of days in a month. The code below is for December in chrome and IE returns 1!
 return 32 - new Date(year, month, 32).getDate(); 

While replaced with this, it seems to work:
 return new Date(year, month+1, 0).getDate(); 

Also setters do not work properly. For example, in chrome, and in IE, the specified code gives surprising results:
 var date = new Date(2014,0,2); date.setDate(1); 

In the opera and firefox troubles have not yet found. In addition, the latest version of jquery ui December 2013 is displayed normally. However, now you have to check the scripts for availability January 1, 2014.
')
How do you deal with this problem?

UPD
Until the revised versions of browsers 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 of determining the number of days in the 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 by 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 is displayed incorrectly - as if it started on Tuesday.

Source: https://habr.com/ru/post/240301/


All Articles