diff --git a/Code.gs b/Code.gs
index d0c0ae9..e9579b6 100644
--- a/Code.gs
+++ b/Code.gs
@@ -49,6 +49,8 @@ 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 "/")
/*
*=========================================
diff --git a/Helpers.gs b/Helpers.gs
index 89fd36d..2c00e87 100644
--- a/Helpers.gs
+++ b/Helpers.gs
@@ -1,3 +1,54 @@
+/**
+ * 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);
+ 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
@@ -255,12 +306,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]);
}
}
}
@@ -271,7 +323,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]);
}
}
}
@@ -712,7 +764,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]);
}
}
}
@@ -930,7 +982,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);
@@ -939,7 +991,13 @@ function sendSummary() {
for (var tgtCal of addedEvents){
body += `
${tgtCal[0]}: ${tgtCal[1].length} added events