Skip to content

Commit cfe9c23

Browse files
committed
delete one of series
Signed-off-by: Alex Ivanov <ai@contributor.pw>
1 parent 6c4baea commit cfe9c23

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"timeZone": "Europe/Moscow",
3+
"exceptionLogging": "STACKDRIVER",
4+
"runtimeVersion": "V8"
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "standalone",
3+
"src": []
4+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
*
3+
* Deletes only specific events from a series that match by date and search term
4+
*
5+
* @param {GoogleAppsScript.Calendar.Calendar} calendar
6+
* @param {Date} start
7+
* @param {Date} end
8+
* @param {string} search
9+
* @returns {GoogleAppsScript.Calendar.CalendarEvent[]}
10+
*/
11+
function deleteEventFromSeries(calendar, start, end, search) {
12+
const options = search ? {} : { search };
13+
const events = calendar.getEvents(start, end, options);
14+
return events.map(
15+
(event) => (event.getEventSeries() ? event.deleteEvent() : undefined, event)
16+
);
17+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: 'Delete specific events from a Google Calendar series'
3+
date: '2021-03-29'
4+
description: ' Checking and deleting only specific events via CalendarApp'
5+
tags: ['calendar']
6+
categories: ['snippets']
7+
---
8+
9+
{{< toc >}}
10+
11+
## Delete specific events from a Google Calendar series
12+
13+
### Snippet
14+
15+
- {{< externalLink >}}
16+
- {{< commentLink >}}
17+
- {{< scrvizLink >}}
18+
19+
{{< codeFromFile "index.js" >}}
20+
21+
### Run it
22+
23+
{{< codeFromFile "run.js" >}}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* global deleteEventFromSeries */
2+
3+
/**
4+
* Run the snippet
5+
*/
6+
function run() {
7+
const calendar = CalendarApp.getCalendarById(
8+
'jllt2nf095qf4ea1pfl1qm1o4o@group.calendar.google.com'
9+
);
10+
const now = new Date();
11+
now.setDate(now.getDate());
12+
const start = new Date(now);
13+
start.setHours(0, 0, 0, 0);
14+
const end = new Date(now);
15+
end.setHours(23, 59, 59, 999);
16+
end.setDate(end.getDate() + 2);
17+
console.log(deleteEventFromSeries(calendar, start, end, 'event'));
18+
}

0 commit comments

Comments
 (0)