iCalendar - Create .ics file using Javascript
function WeeklyCalender(month,day,hour,startTime,endTime,reminderBeforeTime,frequency,summary,additionalAttributes)
{
var dayOfWeek = day;
var startDate = new Date();
if(day!=-1)
startDate.setDate(startDate.getDate() + (dayOfWeek + 7 - startDate.getDay()) % 7)
startDate.setHours(hour,startTime,0,0);
var endDate = new Date();
if(day!=-1)
endDate.setDate(endDate.getDate() + (dayOfWeek + 7 - endDate.getDay()) % 7)
endDate.setHours(hour,endTime,0,0);
var untilDate = new Date();
if(day!=-1)
untilDate.setDate(untilDate.getDate() + (dayOfWeek + 7 - untilDate.getDay()) % 7)
untilDate.setMonth(month);
var blob = new Blob(["BEGIN:VCALENDAR\nBEGIN:VEVENT\nCREATED:"+startDate.toISOString().replaceAll('-','').replaceAll(':','')+"\nDTEND;TZID="+Intl.DateTimeFormat().resolvedOptions().timeZone+":"+endDate.toISOString().replaceAll('-','').replaceAll(':','')+"\nDTSTAMP:"+startDate.toISOString().replaceAll('-','').replaceAll(':','')+"\nDTSTART;TZID="+Intl.DateTimeFormat().resolvedOptions().timeZone+":"+startDate.toISOString().replaceAll('-','').replaceAll(':','')+"\nLAST-MODIFIED:"+startDate.toISOString().replaceAll('-','').replaceAll(':','')+"\nRRULE:FREQ="+frequency+";UNTIL="+untilDate.toISOString().replaceAll('-','').replaceAll(':','')+""+additionalAttributes+"\nSUMMARY:"+summary+"\nBEGIN:VALARM\nTRIGGER:-PT"+reminderBeforeTime+"M\nACTION:DISPLAY\nDESCRIPTION:Reminder\nEND:VALARM\nEND:VEVENT\nEND:VCALENDAR"], { type: "text/calendar" });
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = "sample.ics";
link.click();
}
WeeklyCalender(3,2,21,0,10,2,"WEEKLY","","\nINTERVAL=1;\nWKST=TU;BYDAY=TU")
Comments