From 2cf2ed3471ccb9efc7a8fd47043d41aeb24915be Mon Sep 17 00:00:00 2001 From: FoxtrotSierra6829 Date: Wed, 26 Apr 2023 00:46:27 +0300 Subject: [PATCH 1/5] feat: comprehensive email summary --- Helpers.gs | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/Helpers.gs b/Helpers.gs index 4cfe250..a1d7c88 100644 --- a/Helpers.gs +++ b/Helpers.gs @@ -226,12 +226,13 @@ function processEvent(event, calendarTz){ //------------------------ Send event object to gcal ------------------------ if (needsUpdate){ if (modifyExistingEvents){ + oldEvent = calendarEvents[index] Logger.log("Updating existing event " + newEvent.extendedProperties.private["id"]); newEvent = callWithBackoff(function(){ return Calendar.Events.update(newEvent, targetCalendarId, calendarEvents[index].id); }, defaultMaxRetries); if (newEvent != null && emailSummary){ - modifiedEvents.push([[newEvent.summary, newEvent.start.date||newEvent.start.dateTime], targetCalendarName]); + modifiedEvents.push([[oldEvent.summary, newEvent.summary, oldEvent.start.date||oldEvent.start.dateTime, newEvent.start.date||newEvent.start.dateTime, oldEvent.end.date||oldEvent.end.dateTime, newEvent.end.date||newEvent.end.dateTime, oldEvent.location, newEvent.location, oldEvent.description, newEvent.description], targetCalendarName]); } } } @@ -242,7 +243,7 @@ function processEvent(event, calendarTz){ return Calendar.Events.insert(newEvent, targetCalendarId); }, defaultMaxRetries); if (newEvent != null && emailSummary){ - addedEvents.push([[newEvent.summary, newEvent.start.date||newEvent.start.dateTime], targetCalendarName]); + addedEvents.push([[newEvent.summary, newEvent.start.date||newEvent.start.dateTime, newEvent.end.date||newEvent.end.dateTime, newEvent.location, newEvent.description], targetCalendarName]); } } } @@ -666,7 +667,7 @@ function processEventCleanup(){ }, defaultMaxRetries); if (emailSummary){ - removedEvents.push([[calendarEvents[i].summary, calendarEvents[i].start.date||calendarEvents[i].start.dateTime], targetCalendarName]); + removedEvents.push([[calendarEvents[i].summary, calendarEvents[i].start.date||calendarEvents[i].start.dateTime, calendarEvents[i].end.date||calendarEvents[i].end.dateTime, calendarEvents[i].location, calendarEvents[i].description], targetCalendarName]); } } } @@ -893,7 +894,13 @@ function sendSummary() { for (var tgtCal of addedEvents){ body += `
${tgtCal[0]}: ${tgtCal[1].length} added events
"; } @@ -901,7 +908,18 @@ function sendSummary() { for (var tgtCal of modifiedEvents){ body += `
${tgtCal[0]}: ${tgtCal[1].length} modified events
"; } @@ -909,7 +927,13 @@ function sendSummary() { for (var tgtCal of removedEvents){ body += `
${tgtCal[0]}: ${tgtCal[1].length} removed events
"; } From f93e07cb19c9a6a8ce0c3d3050cbaeb25c4f053c Mon Sep 17 00:00:00 2001 From: FoxtrotSierra Date: Tue, 2 May 2023 17:43:09 +0200 Subject: [PATCH 2/5] feat: custom email subject --- Code.gs | 2 +- Helpers.gs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Code.gs b/Code.gs index 2ce91c3..f77dbdb 100644 --- a/Code.gs +++ b/Code.gs @@ -49,7 +49,7 @@ var addTasks = false; var emailSummary = false; // Will email you when an event is added/modified/removed to your calendar var email = ""; // OPTIONAL: If "emailSummary" is set to true or you want to receive update notifications, you will need to provide your email address - +var customEmailSubject = ""; // OPTIONAL: If you want to change the email subject, provide a custom one here. Default: "GAS-ICS-Sync Execution Summary" /* *========================================= * ABOUT THE AUTHOR diff --git a/Helpers.gs b/Helpers.gs index a1d7c88..0a04c7e 100644 --- a/Helpers.gs +++ b/Helpers.gs @@ -885,7 +885,7 @@ function sendSummary() { var subject; var body; - var subject = `GAS-ICS-Sync Execution Summary: ${addedEvents.length} new, ${modifiedEvents.length} modified, ${removedEvents.length} deleted`; + var subject = `${customEmailSubject ? customEmailSubject : "GAS-ICS-Sync Execution Summary"}: ${addedEvents.length} new, ${modifiedEvents.length} modified, ${removedEvents.length} deleted`; addedEvents = condenseCalendarMap(addedEvents); modifiedEvents = condenseCalendarMap(modifiedEvents); removedEvents = condenseCalendarMap(removedEvents); From 3a956ce8ccb15ac0420ef4e0d4b4ec35abc732b8 Mon Sep 17 00:00:00 2001 From: FoxtrotSierra Date: Tue, 2 May 2023 18:38:14 +0200 Subject: [PATCH 3/5] feat: custom date format --- Code.gs | 1 + Helpers.gs | 61 +++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/Code.gs b/Code.gs index f77dbdb..ac4eb04 100644 --- a/Code.gs +++ b/Code.gs @@ -50,6 +50,7 @@ var addTasks = false; var emailSummary = false; // Will email you when an event is added/modified/removed to your calendar var email = ""; // OPTIONAL: If "emailSummary" is set to true or you want to receive update notifications, you will need to provide your email address var customEmailSubject = ""; // OPTIONAL: If you want to change the email subject, provide a custom one here. Default: "GAS-ICS-Sync Execution Summary" +var dateFormat = "YYYY-MM-DD" // date format in the email summary (e.g. "YYYY-MM-DD", "DD.MM.YYYY", "MM/DD/YYYY". separators are ".", "-" and "/") /* *========================================= * ABOUT THE AUTHOR diff --git a/Helpers.gs b/Helpers.gs index 0a04c7e..d9052b4 100644 --- a/Helpers.gs +++ b/Helpers.gs @@ -1,3 +1,48 @@ +function formatDate(date) { + const year = date.slice(0,4); + const month = date.slice(5,7); + const day = date.slice(8,10); + let formattedDate; + + if (dateFormat == "YYYY/MM/DD") { + formattedDate = year + "/" + month + "/" + day + } + else if (dateFormat == "DD/MM/YYYY") { + formattedDate = day + "/" + month + "/" + year + } + else if (dateFormat == "MM/DD/YYYY") { + formattedDate = month + "/" + day + "/" + year + } + else if (dateFormat == "YYYY-MM-DD") { + formattedDate = year + "-" + month + "-" + day + } + else if (dateFormat == "DD-MM-YYYY") { + formattedDate = day + "-" + month + "-" + year + } + else if (dateFormat == "MM-DD-YYYY") { + formattedDate = month + "-" + day + "-" + year + } + else if (dateFormat == "YYYY.MM.DD") { + formattedDate = year + "." + month + "." + day + } + else if (dateFormat == "DD.MM.YYYY") { + formattedDate = day + "." + month + "." + year + } + else if (dateFormat == "MM.DD.YYYY") { + formattedDate = month + "." + day + "." + year + } + + if (date.length < 11) { + return formattedDate + } + + const time = date.slice(11,16) + const timeZone = date.slice(19) + + return formattedDate + " at " + time + " (UTC" + (timeZone == "Z" ? "": timeZone) + ")" +} + + /** * Takes an intended frequency in minutes and adjusts it to be the closest * acceptable value to use Google "everyMinutes" trigger setting (i.e. one of @@ -896,8 +941,8 @@ function sendSummary() { for (var addedEvent of tgtCal[1]){ body += "
  • " + "Name: " + addedEvent[0][0] + "
    " - + "Start: " + addedEvent[0][1] + "
    " - + "End: " + addedEvent[0][2] + "
    " + + "Start: " + formatDate(addedEvent[0][1]) + "
    " + + "End: " + formatDate(addedEvent[0][2]) + "
    " + (addedEvent[0][3] ? ("Location: " + addedEvent[0][3] + "
    ") : "") + (addedEvent[0][4] ? ("Description: " + addedEvent[0][4] + "
    ") : "") + "
  • "; @@ -911,10 +956,10 @@ function sendSummary() { body += "
  • " + (modifiedEvent[0][0] != modifiedEvent[0][1] ? ("Name: " + modifiedEvent[0][0] + "
    ") : "") + "Name: " + modifiedEvent[0][1] + "
    " - + (modifiedEvent[0][2] != modifiedEvent[0][3] ? ("Start: " + modifiedEvent[0][2] + "
    ") : "") - + " Start: " + modifiedEvent[0][3] + "
    " - + (modifiedEvent[0][4] != modifiedEvent[0][5] ? ("End: " + modifiedEvent[0][4] + "
    ") : "") - + " End: " + modifiedEvent[0][5] + "
    " + + (modifiedEvent[0][2] != modifiedEvent[0][3] ? ("Start: " + formatDate(modifiedEvent[0][2]) + "
    ") : "") + + " Start: " + formatDate(modifiedEvent[0][3]) + "
    " + + (modifiedEvent[0][4] != modifiedEvent[0][5] ? ("End: " + formatDate(modifiedEvent[0][4]) + "
    ") : "") + + " End: " + formatDate(modifiedEvent[0][5]) + "
    " + (modifiedEvent[0][6] != modifiedEvent[0][7] ? ("Location: " + (modifiedEvent[0][6] ? modifiedEvent[0][6] : "") + "
    ") : "") + (modifiedEvent[0][7] ? (" Location: " + modifiedEvent[0][7] + "
    ") : "") + (modifiedEvent[0][8] != modifiedEvent[0][9] ? ("Description: " + (modifiedEvent[0][8] ? modifiedEvent[0][8] : "") + "
    ") : "") @@ -929,8 +974,8 @@ function sendSummary() { for (var removedEvent of tgtCal[1]){ body += "
  • " + "Name: " + removedEvent[0][0] + "
    " - + "Start: " + removedEvent[0][1] + "
    " - + "End: " + removedEvent[0][2] + "
    " + + "Start: " + formatDate(removedEvent[0][1]) + "
    " + + "End: " + formatDate(removedEvent[0][2]) + "
    " + (removedEvent[0][3] ? ("Location: " + removedEvent[0][3] + "
    ") : "") + (removedEvent[0][4] ? ("Description: " + removedEvent[0][4] + "
    ") : "") + "
  • "; From 4ec641a6e705f1aa87e446dfd41c8d129f4ed080 Mon Sep 17 00:00:00 2001 From: FoxtrotSierra Date: Tue, 2 May 2023 19:25:02 +0200 Subject: [PATCH 4/5] refactor: add back line break --- Code.gs | 1 + 1 file changed, 1 insertion(+) diff --git a/Code.gs b/Code.gs index ac4eb04..b5ac866 100644 --- a/Code.gs +++ b/Code.gs @@ -51,6 +51,7 @@ var emailSummary = false; // Will email you when an event is add var email = ""; // OPTIONAL: If "emailSummary" is set to true or you want to receive update notifications, you will need to provide your email address var customEmailSubject = ""; // OPTIONAL: If you want to change the email subject, provide a custom one here. Default: "GAS-ICS-Sync Execution Summary" var dateFormat = "YYYY-MM-DD" // date format in the email summary (e.g. "YYYY-MM-DD", "DD.MM.YYYY", "MM/DD/YYYY". separators are ".", "-" and "/") + /* *========================================= * ABOUT THE AUTHOR From d49770d4a2a26703e0a6e518f63a95cfbf7f6817 Mon Sep 17 00:00:00 2001 From: FoxtrotSierra Date: Tue, 2 May 2023 19:44:39 +0200 Subject: [PATCH 5/5] docs: add function documentation --- Helpers.gs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Helpers.gs b/Helpers.gs index d9052b4..e7c7876 100644 --- a/Helpers.gs +++ b/Helpers.gs @@ -1,3 +1,9 @@ +/** + * Formats the date and time according to the format specified in the configuration. + * + * @param {string} date The date to be formatted. + * @return {string} The formatted date string. + */ function formatDate(date) { const year = date.slice(0,4); const month = date.slice(5,7);