Skip to content

Instantly share code, notes, and snippets.

@remisarrailh
Created June 3, 2019 10:54
Show Gist options
  • Save remisarrailh/ff9c61ebfccd0363e22a37b6a5bfdce1 to your computer and use it in GitHub Desktop.
Save remisarrailh/ff9c61ebfccd0363e22a37b6a5bfdce1 to your computer and use it in GitHub Desktop.
// Retrieve description
description_raw = msg.payload.split("SUMMARY:");
var description = [];
description_raw.forEach(function (item, index) {
if(index !== 0){
description.push(item.split("\n")[0].trim());
}
});
// Retrieve date
date_raw = msg.payload.split("DTSTART;");
var message = "Here is the list of worshops:\n------------------------\n";
date_raw.forEach(function (item, index) {
if(index !== 0){
icalStr = item.split("\n")[0].trim();
icalStr = item.split(":")[1].trim();
//Convert time
var strYear = icalStr.substr(0,4);
var strMonth = icalStr.substr(4,2);
var strDay = icalStr.substr(6,2);
//Convert date to days
strDate = strMonth + "/" + strDay + "/" + strYear;
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
strDayFull = days[new Date(strDate).getDay()];
//Convert date to month
var month = ['January', 'February', 'March', 'April', 'May', 'Juin', 'July', 'August', 'September', 'October', 'November', 'December'];
strMonthFull = month[new Date(strDate).getMonth()];
message += description[index-1] + " --> " + strDayFull + " " + strDay + " " + strMonthFull + "\n";
}
});
//End message
message += "\n More info on [ADDRESS]";
//Copy message to new_calendrier variable
flow.set("new_calendar", message);
return msg;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment