Skip to content

Commit 198ec0b

Browse files
Merge pull request #69 from contributorpw/edits
2 parents 6c4baea + f1fd1e7 commit 198ec0b

File tree

11 files changed

+129
-1
lines changed

11 files changed

+129
-1
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+
}

snippets/common_js/date-range-iterator/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ date: '2021-04-19'
44
description: 'Gets an iterator of dates for the specified range.'
55
tags: ['js', 'common']
66
categories: ['snippets']
7-
images: ['./snippets/sheets/unlink_urls/screenrecord.gif']
7+
images: ['./snippets/sheets/date-range-iterator/screenshot.png']
88
---
99

1010
{{< toc >}}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"timeZone": "Europe/Moscow",
3+
"dependencies": {},
4+
"exceptionLogging": "STACKDRIVER",
5+
"runtimeVersion": "V8"
6+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "standalone"
3+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Converts date-time to numeric Sheets format
3+
*
4+
* @param {(number|Date)} date JS Date or time in ms
5+
* @param {number} timezoneOffset
6+
* @return {number} Google Sheets Date number
7+
*/
8+
function toGoogleSheetsDateNumber(date, timezoneOffset) {
9+
const _date = new Date(date);
10+
timezoneOffset = timezoneOffset || _date.getTimezoneOffset();
11+
const _start = new Date(Date.UTC(1899, 11, 30, 0, 0, 0, 0));
12+
return ((_date.getTime() - _start.getTime()) / 60000 - timezoneOffset) / 1440;
13+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: 'Sheets datetime converter'
3+
date: '2021-04-20'
4+
description: 'Converts date-time to Sheets format.'
5+
tags: ['js', 'common']
6+
categories: ['snippets']
7+
---
8+
9+
{{< toc >}}
10+
11+
## Sheets datetime converter
12+
13+
![Snippet of Sheets datetime converter](./screenshot.png)
14+
15+
### Snippet
16+
17+
- {{< externalLink >}}
18+
- {{< commentLink >}}
19+
- {{< scrvizLink >}}
20+
21+
{{< codeFromFile "index.js" >}}
22+
23+
### Run it
24+
25+
{{< codeFromFile "run.js" >}}
26+
27+
### Relations
28+
29+
- [google apps script - How to get a date format string from a sheet cell? - Stack Overflow](https://stackoverflow.com/questions/33809229/how-to-get-a-date-format-string-from-a-sheet-cell/33813783#33813783)
30+
- [javascript - Converting Google spreadsheet date into a JS Date object? - Stack Overflow](https://stackoverflow.com/questions/14363073/converting-google-spreadsheet-date-into-a-js-date-object)

0 commit comments

Comments
 (0)