Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some calendars won't load #839

Closed
fewieden opened this issue Apr 9, 2017 · 24 comments
Closed

Some calendars won't load #839

fewieden opened this issue Apr 9, 2017 · 24 comments

Comments

@fewieden
Copy link
Contributor

fewieden commented Apr 9, 2017

Lately a lot of users complain about that some of their calendar files wont be loaded anymore in v2.1.1

https://forum.magicmirror.builders/topic/2221/after-upgrade-v2-1-1-multiple-calendars-not-displaying
https://forum.magicmirror.builders/topic/2208/calendar-shows-no-entries-after-mm-update

@coderaaron
Copy link

coderaaron commented Apr 11, 2017

So, here is what I'm getting when I do npm start dev will do some more investigating when I have time but I thought I'd report it in case anyone with more experience knows off the top of their head what the problem is.

Create new calendar fetcher for url: https://outlook.office365.com/owa/calendar/<REDACTED>@<REDACTED>/S-1-8-117873446-3978456252-3857600756-3375899348/reachcalendar.ics - Interval: 300000
Create new news fetcher for url: http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml - Interval: 300000
Whoops! There was an uncaught exception...
TypeError: curr.exdates[i].toISOString is not a function
    at Object.ical.objectHandlers.END (/home/pi/MagicMirror/modules/default/calendar/vendor/ical.js/node-ical.js:44:44)
    at Object.handleObject (/home/pi/MagicMirror/modules/default/calendar/vendor/ical.js/ical.js:267:41)
    at Object.parseICS (/home/pi/MagicMirror/modules/default/calendar/vendor/ical.js/ical.js:308:20)
    at Request._callback (/home/pi/MagicMirror/modules/default/calendar/vendor/ical.js/node-ical.js:11:24)
    at Request.self.callback (/home/pi/MagicMirror/node_modules/request/request.js:188:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (/home/pi/MagicMirror/node_modules/request/request.js:1171:10)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues```

@coderaaron
Copy link

After a little more digging, it looks like this is caused by recurring events that have more than one exdate (exception date)...I started debugging the ical.js and node-ical.js, but need to do some work so I can't go any further today

@DutchDynamics
Copy link

Hi, I also have the same problem. It looks like there are different ways to deal with multiple EXDATA in the ics file.
Some calendars return it like this:
EXDATE;TZID=South Africa Standard Time:20170403T060000,20170410T060000,20170417T060000,20170501T060000

others return it like:
EXDATE;TZID=South Africa Standard Time:20170403T060000
EXDATE;TZID=South Africa Standard Time:20170410T060000
EXDATE;TZID=South Africa Standard Time:20170417T060000
EXDATE;TZID=South Africa Standard Time:20170501T060000

The last method is working fine, but the first method, is causing the toISOstring error.

@coderaaron
Copy link

coderaaron commented Apr 17, 2017

So this is SUPER hacky but it got my calendar to load. The only thing is it takes just the first exdate and ignores the rest so consider it an alpha-version, not sure if I'll have to time make it better so if anyone else has the time I'd appreciate the help:

(Splice function from this Stack overflow question)

MagicMirror/modules/default/calendar/vendor/ical.js:200

if (!String.prototype.splice) {
    /**
     * {JSDoc}
     *
     * The splice() method changes the content of a string by removing a range of
     * characters and/or adding new characters.
     *
     * @this {String}
     * @param {number} start Index at which to start changing the string.
     * @param {number} delCount An integer indicating the number of old chars to remove.
     * @param {string} newSubStr The String that is spliced in.
     * @return {string} A new string with the spliced substring.
     */
    String.prototype.splice = function(start, delCount, newSubStr) {
        return this.slice(0, start) + newSubStr + this.slice(start + Math.abs(delCount));
    };
}

  // EXDATE is an entry that represents exceptions to a recurrence rule (ex: "repeat every day except on 7/4").
  // There can be more than one of these in a calendar record, so we create an array of them.
  // The index into the array is the ISO string of the date itself, for ease of use.
  // i.e. You can check if ((curr.exdate != undefined) && (curr.exdate[date iso string] != undefined)) to see if a date is an exception.
  var exdateParam = function (name) {
      return function (val, params, curr) {
          var exdate = new Array();
          dateParam(name)(val, params, exdate);
          curr[name] = curr[name] || [];
          date_array = [];
          if(typeof exdate[name]=='string'){
             exdate_array=exdate[name].split(',');
             exdate_string=exdate_array[0];
             exdate[name]=exdate_string.splice(13,0,":").splice(11,0,":").splice(6,0,"-").splice(4,0,"-");
          } else {
             curr[name][exdate[name].toISOString()] = exdate[name];
          }
          return curr;
      }
  }`

@DutchDynamics
Copy link

DutchDynamics commented Apr 18, 2017

Hi,

Took your example and played around a bit. This is loading my calendar, and it's including all exceptions not only the first one

    // EXDATE is an entry that represents exceptions to a recurrence rule (ex: "repeat every day except on 7/4").
    // There can be more than one of these in a calendar record, so we create an array of them.
    // The index into the array is the ISO string of the date itself, for ease of use.
    // i.e. You can check if ((curr.exdate != undefined) && (curr.exdate[date iso string] != undefined)) to see if a date is an exception.
    var exdateParam = function (name) {
        return function (val, params, curr) {
            var index;
            var tmpDates = new Array();
       
            tmpDates = val.split(",");

            for (index = 0; index < tmpDates.length; ++index) {
                var exdate = new Array();
                dateParam(name)(tmpDates[index], params, exdate);
                curr[name] = curr[name] || [];
                curr[name][exdate[name].toISOString()] = exdate[name];
            }                   
       
            return curr;
        }
    }

@MrXfree11
Copy link

MrXfree11 commented Apr 20, 2017

Hi, any chance to give me an hint which file to edit, to apply that super hacky workarround? The publicly published .ical file from my Exchange 2016 Calendar creates exactly the same error since the MM upgrade:

Whoops! There was an uncaught exception... TypeError: curr.exdates[i].toISOString is not a function

@coderaaron
Copy link

The file to edit is MagicMirror/modules/default/calendar/vendor/ical.js

@MrXfree11
Copy link

AWESOME! works like a charm. Thanks a lot.

Cheers.

@mitch1138
Copy link

tgeimer suggested editing
ORDINAL_BASE: new Date(1970, 0, 1),
in
/home/pi/MagicMirror/node_modules/rrule-alt/lib/rrule.js
to an earlier date. I used 1000 and it resolved my issue.

@roramirez
Copy link
Contributor

I think to be this we need fork the actual repository and apply the patch or create a rules for add this path. cc @fewieden @amcolash

@amcolash
Copy link
Contributor

I made an issue on the rrule repo here, maybe we can get official change instead of a local version. I was looking into the code and it doesn't look like it would be easy to inject our own ORDINAL_BASE. Seems like a patch, fork or local copy are the options.

@MichMich
Copy link
Collaborator

I think the best approach is indeed forking one of the libs and maintaining it ourselves. Any volunteer? 😄

@Dup0n7
Copy link

Dup0n7 commented Apr 25, 2017

Where in MagicMirror/modules/default/calendar/vendor/ical.js do you add those lines @DutchDynamics ?

@DutchDynamics
Copy link

Hi,

I attached the versions of ical.js and node-ical.js that i'm currently using
The change I made is in the method 'exdateParam' in the ical.js
From line 182 till 202

ical.js.zip

@roramirez
Copy link
Contributor

Note: I've testing the patch proposed before
roramirez/rrule-alt@7e1cd58
and the tests of rrule-alt are broke inside the lib.

@GobleSt
Copy link

GobleSt commented May 1, 2017

Edits by coderaaron and DutchDynamics fixed this for me also as I had the same exact issue.

Thanks all!!!

@deadherring
Copy link

Thanks @coderaaron and @DutchDynamics!! I've been having the same problem with the exchange calendar and copied your files to my magic mirror and now it's working!

@elmerito25
Copy link

Same here! Thanks a lot!

@MichMich
Copy link
Collaborator

@roramirez Can I close this issue?

@RamblingGeekUK
Copy link

I was trying to use ical from outlook.com and it didn't work until I replaced the .js files provided by @coderaaron and @DutchDynamics, thanks!

@dandickout
Copy link

Fixed it for me :)

@MichMich
Copy link
Collaborator

MichMich commented Sep 6, 2017

Closed due to inactivity. Feel free to reopen.

@Munich81
Copy link

Just ran into the same problem with the current verion. Any reason why the fix didn't make it into master?

@lawrence-jeff
Copy link

lawrence-jeff commented Sep 8, 2018

Also just ran into this with an outlook.com calendar. Fix in this thread did correct it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests