forked from ryanmwangi/CalMerger
check if calendar is date based or event based
This commit is contained in:
parent
698494dc27
commit
79c5183971
28
server.js
28
server.js
|
@ -87,7 +87,33 @@ app.post('/merge', async (req, res) => {
|
||||||
|
|
||||||
// Parse calendar data
|
// Parse calendar data
|
||||||
validResults.forEach((result) => {
|
validResults.forEach((result) => {
|
||||||
const parsedCalendar = ical.parseICS(result.data);
|
const parsed = ical.parse(result.data);
|
||||||
|
const component = new ICAL.Component(parsed);
|
||||||
|
const events = component.getAllSubcomponents('vevent');
|
||||||
|
|
||||||
|
events.forEach((event) => {
|
||||||
|
const vevent = new ICAL.Event(event);
|
||||||
|
const start = vevent.startDate.toJSDate();
|
||||||
|
const end = vevent.endDate.toJSDate();
|
||||||
|
const summary = result.override ? result.prefix : `${result.prefix} ${vevent.summary}`;
|
||||||
|
|
||||||
|
if (vevent.startDate.isDate) {
|
||||||
|
calendar.createEvent({
|
||||||
|
start: start.toISOString().split('T')[0],
|
||||||
|
end: end.toISOString().split('T')[0],
|
||||||
|
summary: summary,
|
||||||
|
allDay: true,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
calendar.createEvent({
|
||||||
|
start: start,
|
||||||
|
end: end,
|
||||||
|
summary: summary,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
Object.keys(parsedCalendar).forEach((key) => {
|
Object.keys(parsedCalendar).forEach((key) => {
|
||||||
const event = parsedCalendar[key];
|
const event = parsedCalendar[key];
|
||||||
const start = new Date(event.start);
|
const start = new Date(event.start);
|
||||||
|
|
Loading…
Reference in New Issue