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

Script stops execution of events if iCal has a color unknown to Google Calendar #308

Closed
obbardc opened this issue Jan 26, 2023 · 11 comments · Fixed by #369
Closed

Script stops execution of events if iCal has a color unknown to Google Calendar #308

obbardc opened this issue Jan 26, 2023 · 11 comments · Fixed by #369
Labels
bug Something isn't working

Comments

@obbardc
Copy link

obbardc commented Jan 26, 2023

Hi! I am really loving this script, thanks for supporting it.

It seems that there are two issues I want to create here:

  1. (a side note) If an event fails to be added to the calander, it stops executing all other events. If this happens early in the list, then the script effectively ignores all the other events to process. Would it be worth having a try/catch around each event in the for loop?
      vevents.forEach(function(e){
        processEvent(e, calendarTz);
      });
  1. iCal events with an unsupported color (e.g. khaki) cause the Google API to return an error and this error is just thrown and then the script just exits (see point 1 above). We should sanitise the colorId and make sure that the Google API supports that colour. For now, I have simply commented these three lines out since my events don't need colours.
  if (event.hasProperty('color')){
    newEvent.colorId = event.getFirstPropertyValue('color').toString();
  }
@obbardc obbardc added the bug Something isn't working label Jan 26, 2023
@obbardc
Copy link
Author

obbardc commented Jan 26, 2023

An example ical event (see COLOR:khaki):

BEGIN:VEVENT
UID:ID
DTSTAMP:20221108T125544Z
DTSTART;TZID=Europe/London:20221111T100000
DTEND;TZID=Europe/London:20221111T103000
SEQUENCE:3
SUMMARY:summary
LOCATION:location
TRANSP:OPAQUE
CLASS:PUBLIC
CREATED:20221109T105640Z
LAST-MODIFIED:20221109T105657Z
COLOR:khaki
ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;CN=Name;CUTYPE=INDIVIDUAL:mailto:email@example.com
ORGANIZER:mailto:email@example.com
END:VEVENT

@derekantrican
Copy link
Owner

May be a dupe of #93

@simonegiusti
Copy link

Hello,
I have a problem with COLOR: tag ...

This works:

BEGIN:VCALENDAR
PRODID:rockjob calendar2
VERSION:2.0
METHOD:REQUEST
X-WR-CALNAME:rockjob calendar2
X-WR - TimeZone: UTC
BEGIN:VEVENT
UID:260
DTSTAMP:20230923T174352Z
CREATED:20230923T174352Z
LOCATION:Sala Prove - RHO
SEQUENCE:20230923174352
STATUS:CONFIRMED
LAST-MODIFIED:20230923T174352Z
DESCRIPTION:
SUMMARY:PP, RHO - Sala Prove
DTSTART:20231023
DTEND:20231023
X-FUNAMBOL-ALLDAY:TRUE
X-MICROSOFT-CDO-ALLDAYEVENT:TRUE
TRANSP:OPAQUE
END:VEVENT

This does not:

BEGIN:VCALENDAR
PRODID:rockjob calendar2
VERSION:2.0
METHOD:REQUEST
X-WR-CALNAME:rockjob calendar2
X-WR - TimeZone: UTC
BEGIN:VEVENT
UID:260
DTSTAMP:20230923T174352Z
CREATED:20230923T174352Z
COLOR:RED
LOCATION:Sala Prove - RHO
SEQUENCE:20230923174352
STATUS:CONFIRMED
LAST-MODIFIED:20230923T174352Z
DESCRIPTION:
SUMMARY:PP, RHO - Sala Prove
DTSTART:20231023
DTEND:20231023
X-FUNAMBOL-ALLDAY:TRUE
X-MICROSOFT-CDO-ALLDAYEVENT:TRUE
TRANSP:OPAQUE
END:VEVENT

this is the error:
image

Any suggestion appreciated ..

@obbardc
Copy link
Author

obbardc commented Sep 23, 2023

I think we need to ignore the colour tag if it's not able to be mapped to a gcal colour.

@jonas0b1011001
Copy link
Collaborator

@simonegiusti Please test the following change:

Replace Helpers.gs lines 475-477

  if (event.hasProperty('color')){
    newEvent.colorId = event.getFirstPropertyValue('color').toString();
  }

with:

  if (event.hasProperty('color')){
    let colorID = event.getFirstPropertyValue('color').toString();
    if (Object.keys(CalendarApp.EventColor).includes(colorID)){
      newEvent.colorId = CalendarApp.EventColor[colorID];
    }else if(Object.values(CalendarApp.EventColor).includes(colorID)){
      newEvent.colorId = colorID;
    }; //else unsupported value
  }

@simonegiusti
Copy link

@simonegiusti Please test the following change:

Replace Helpers.gs lines 475-477

  if (event.hasProperty('color')){
    newEvent.colorId = event.getFirstPropertyValue('color').toString();
  }

with:

  if (event.hasProperty('color')){
    let colorID = event.getFirstPropertyValue('color').toString();
    if (Object.keys(CalendarApp.EventColor).includes(colorID)){
      newEvent.colorId = CalendarApp.EventColor[colorID];
    }else if(Object.values(CalendarApp.EventColor).includes(colorID)){
      newEvent.colorId = colorID;
    }; //else unsupported value
  }

Now it works perfectly !!
Many thanks ...

@obbardc
Copy link
Author

obbardc commented Sep 24, 2023

This should be open until it's merged right ?

@jonas0b1011001
Copy link
Collaborator

@obbardc Does this fix your 2. issue aswell?

@obbardc
Copy link
Author

obbardc commented Sep 27, 2023

@jonas0b1011001 yeah, it just doesn't set the colour as expected :-) Can you open a PR, please ?

@jonas0b1011001
Copy link
Collaborator

@jonas0b1011001 yeah, it just doesn't set the colour as expected :-) Can you open a PR, please ?

Well we are limited to the colors google offers us. We have discussed manually matching colors a while ago but i have no idea how to do that.

@obbardc
Copy link
Author

obbardc commented Sep 27, 2023

@jonas0b1011001 yeah, it just doesn't set the colour as expected :-) Can you open a PR, please ?

Well we are limited to the colors google offers us. We have discussed manually matching colors a while ago but i have no idea how to do that.

No, I mean with this patch it is fine. If the ics has a colour which google doesn't understand, it sets it to default. Which is good for me.

I don't care about colours in the destination calendar anyway ;-).

@Lonestarjeepin Lonestarjeepin linked a pull request Sep 29, 2023 that will close this issue
derekantrican pushed a commit that referenced this issue Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants