heskja / MMM-CalendarWeek

Alternative calendar module for MagicMirror.
MIT License
53 stars 22 forks source link

Calendar entries are displayed in inviter's timezone #42

Open kjendal opened 4 years ago

kjendal commented 4 years ago

I'm using icals published from Office365. Events are shown in the originators timezone (not local timezone). Using latest release. Cloned 6/28/2020.

kjendal commented 4 years ago

After some additional testing, it looks like the timezone is ignored and the time is used and local timezone is assumed.

My timezone is US EST. Calendar entries with DTSTART;TZID=Eastern Standard Time:20200610T070000 DTEND;TZID=Eastern Standard Time:20200610T083000 are displayed correctly.

Here is a snippet of the ICS that is related to the problem:

BEGIN:VEVENT UID:D08BB6CB0CBB4600A25486726835A759HLLORA SUMMARY:[EXTERNAL]TC Monthly Telechat meeting DTSTART;TZID=America/Los_Angeles:20200603T070000 DTEND;TZID=America/Los_Angeles:20200603T080000 CLASS:PUBLIC PRIORITY:5 DTSTAMP:20200629T131911Z TRANSP:OPAQUE STATUS:CONFIRMED SEQUENCE:0

...

kjendal commented 4 years ago

I have this working now, but its a bit of a hack. For those interested: ical.js does not handle timezones at all to address this, start with the patch from https://github.com/yyolk/node-ical-improved but support timeformats without 'Z' notation (UTC)

//typical RFC date-time format
      var comps = /^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(Z)?$/.exec(val);
      if (comps !== null) {
        if (comps[7] == 'Z'){ // GMT
          //newDate = new Date(Date.UTC(
            //parseInt(comps[1], 10),
            //parseInt(comps[2], 10)-1,
            //parseInt(comps[3], 10),
            //parseInt(comps[4], 10),
            //parseInt(comps[5], 10),
            //parseInt(comps[6], 10 )
          //));
          // TODO add tz
        } else {
          //newDate = new Date(
            //parseInt(comps[1], 10),
            //parseInt(comps[2], 10)-1,
            //parseInt(comps[3], 10),
            //parseInt(comps[4], 10),
            //parseInt(comps[5], 10),
            //parseInt(comps[6], 10)
          //);            
        }
        newDate = require('moment-timezone').tz(val.toString(), (parseParams(params).TZID || '')).tz('America/New_York').toDate();
        newDate = addTZ(newDate, params);
    }

Also, Outlook (at least) uses its own (apparently) TZID notation. The few that I tried need to be added to the timezone data from moment-timezone:

 // link some timezones for MS Outlook iCal
      var moment = require('moment-timezone');
        moment.tz.link([
        'America/New_York|Eastern Standard Time',
        'America/New_York|Eastern Daylight Time',
        'America/Chicago|Central Standard Time',
        'America/Chicago|Central Daylight Time',
        'America/Denver|Mountain Standard Time',
        'America/Denver|Mountain Daylight Time',
        'America/Los_Angeles|Pacific Standard Time',
        'America/Los_Angeles|Pacific Daylight Time',
        'Europe/Brussels|W. Europe Standard Time'
        ]);

I'm sure there is a better way to do this, but at least it is working...

I have a complete list outlook/MS timezone names to moment-timezone mappings if anyone is interested.