robmonie / jquery-week-calendar

Now actively maintained in the following fork - https://github.com/themouette/jquery-week-calendar
388 stars 391 forks source link

Wrong _dateFirstDayOfWeek calculation due to daylight saving time #2

Closed mschinca closed 14 years ago

mschinca commented 14 years ago

I'm testing this behavior in version 1.2.0, I'm sorry I cannot test this in head, so please close the bug if it has already been fixed. When switching to daylight saving time, calendar events won't be displayed and column day headers are wrong, only for that week. This is due to wrong dateFirstDayOfWeek calculation. I created a quick workaround for this by changing the function _dateFirstDayOfWeek in the following way. I noticed that also the _dateLastDayOfWeek function is affected by a similar problem when switching from daylight saving time back to normal time. I'm sorry I cannot produce a valid patch, I hope it can be useful anyway.

Regards, Marco.

file jquery.weekcalendar, version 1.2.0, line 968 / * returns the date on the first millisecond of the week / _dateFirstDayOfWeek : function(date) {

            var midnightCurrentDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
            var currentDayOfWeek = midnightCurrentDate.getDay();
            var millisToSubtract = currentDayOfWeek * 86400000;
            var dateTimeZoneCheck = new Date(midnightCurrentDate.getTime() - millisToSubtract);
            // workaround for daylight saving time
            if (dateTimeZoneCheck.getHours()==23) {
              dateTimeZoneCheck = new Date(dateTimeZoneCheck.getTime() + 3600000);
            }
            return dateTimeZoneCheck;

        },
mschinca commented 14 years ago

UPDATE: I believe that the bug is still in 1.2.2. You can see the bug also in demo: http://jquery-week-calendar.s3.amazonaws.com/weekcalendar.html Go to the week when the daylight saving time begins, then go to the following week and see what happens. For example, I am at GMT +1, daylight saving time starts on Mar 27, 2010. If go to that week, the first day of week is Sunday Mar 21, 2010 and the last day is Saturday Mar 27, 2010. This is correct, but going to the following week shows up the bug, in fact It starts on Saturday Mar 27, 2010 and ends on Friday Apr 02, 2010. The following week starts on Sunday Apr 04, 2010 and ends on Saturday Apr 10, 2010. So Saturday Mar 27, 2010 is displayed in two different weeks and Apr 3, 2010 is never displayed.

robmonie commented 14 years ago

I think this is fixed now and checked in. Note that what is currently in the master branch is dependant on jquery 1.4 and ui 1.8rc3.

The final solution is different to that posted above so if you can confirm that this fixes your specific problem that would be great.

mschinca commented 14 years ago

I tested only the new implementation of_dateFirstDayOfWeek, replacing it in the old code, and I confirm it fixes the issue, thanks.

robmonie commented 14 years ago

Glad to hear it. Thanks for confirming this for me.

anandns28 commented 10 years ago

This was a great help to resolve the wrong first day of the week issue when DST is enabled. Another issue I am facing is the hour is shifted earlier to 1 when DST is enabled only for the first day of the week. Can anyone respond on this please?