jekor / drcal

A Minimalist JavaScript Calendar (not a date picker)
http://www.minjs.com/#drcal
MIT License
26 stars 5 forks source link

October issue #7

Open metalgigio opened 6 years ago

metalgigio commented 6 years ago

On October 2017 it show two times 29...

metalgigio commented 6 years ago

and it miss the 4 of november 2017

midzer commented 6 years ago

Hello @metalgigio hmm, strange bug. I have a working implementation running over at https://feuerwehr-eisolzried.de/ and do not experience your issue.

Do you have latest drcal installed?

metalgigio commented 6 years ago

hi, i used an old version of drcall but the problem is even in last. I discovered that the problem is related with Daylight saving time, couse the 29 here in italy there's the hour change so the day will last 25h. So the problem is in that part of the code:

for (var i = 0; i < 7; i++) {
                    var cell = $('<td date="' + iso8601(day) + '" year="' + day.getFullYear() + '" month="' + (day.getMonth() + 1) + '" day="' + day.getDate() + '"></td>').appendTo(week);
                    day = new Date(day.getTime() + 86400000);
                }

that i solved with a function:

function renderWeek(date) {
                var day = date;
                var week = $('<tr></tr>');
                for (var i = 0; i < 7; i++) {
                    var cell = $('<td date="' + iso8601(day) + '" year="' + day.getFullYear() + '" month="' + (day.getMonth() + 1) + '" day="' + day.getDate() + '"></td>').appendTo(week);
                    day = addDays(day, 1);   //FIX
                }
                return week;
              }

              function addDays(date, amount) {
                var tzOff = date.getTimezoneOffset() * 60 * 1000,
                    t = date.getTime(),
                    d = new Date(),
                    tzOff2;

                t += (1000 * 60 * 60 * 24) * amount;
                d.setTime(t);

                tzOff2 = d.getTimezoneOffset() * 60 * 1000;
                if (tzOff != tzOff2) {
                  var diff = tzOff2 - tzOff;
                  t += diff;
                  d.setTime(t);
                }

                return d;
              }
midzer commented 6 years ago

I'm living in same timezone as you, @metalgigio Really suggest to test your implementation with latest non-jQuery drcal as my calendar linked above is working as expected for me.

In case there are still issues we can further dig into code and prepare a PR if need be.

Greetings from Munich midzer

metalgigio commented 6 years ago

maybe u already solved the bug couse in https://feuerwehr-eisolzried.de/ i see calendar correct. I've looked at demo link http://www.minjs.com/#drcal thinking that it was the last version of drcal but maybe it's not. (if u look at the demo page u will see two 29 of october)

midzer commented 6 years ago

Thanks for your link to demo page. Yeah, clearly a bug with drcal version loaded there, perhaps not the latest version.

I hope @jekor can take a look into this issue. Meanwhile, you can try to use https://github.com/midzer/eisolzried/blob/master/_assets/js/drcal.js which might solve issue for your site.