Last active
June 13, 2025 15:15
Revisions
-
bene-we revised this gist
Jul 26, 2024 . 1 changed file with 66 additions and 37 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,48 +1,77 @@ const CALENDAR_ID = "calendarIdGoesHere@group.calendar.google.com"; const TAG_NAME = 'calculatedAge'; const FORCE_OVERWRITE = false; // Control for how many years in the future the age should be calculated // Set to `1` to only cover the current year const CALCULATE_FOR_YEARS = 2; // Set to `true` to enable debug logging const DEBUG = false; /* * Calculate the age of birthday people in each year and add a short note in the description */ function calculateAge() { // Get Calendar 'Birthdays' const birthdayCal = CalendarApp.getCalendarById(CALENDAR_ID); const yearOfExecution = (new Date()).getFullYear() for (var i = 0; i < CALCULATE_FOR_YEARS; i++) { // Select date range of the year that is currently processed const currentYear = yearOfExecution + i; const start = new Date(currentYear + '-01-01'); const end = new Date(currentYear + '-12-31'); // Fetch events from Birthday Calendar var birthdays = birthdayCal.getEvents(start, end); // Filter Birthdays out of Default Calendar (if no specific Birthday Calendar is present) // birthdays = birthdays.filter(filterBirthdays); if (DEBUG) { Logger.log(`Scanning ${birthdays.length} birthdays in year ${currentYear} ...`) } for (var j = 0; j < birthdays.length; j++) { e = birthdays[j]; // Year of birth is stored in the Location field of the event const birthYear = e.getLocation() const birthYearIsNotEmpty = birthYear !== "" if (birthYearIsNotEmpty) { const descriptionIsEmpty = e.getDescription() === "" const tagIsEmpty = isNaN(parseInt(e.getTag(TAG_NAME))) // Calculate the age if it has not been done before OR `FORCE_OVERWRITE` is true if ((descriptionIsEmpty && tagIsEmpty) || FORCE_OVERWRITE) { const calculatedAge = Math.round(currentYear - birthYear); // Customize the description here const description = e.getTitle() + ' wird heute ' + calculatedAge + ' Jahre!' e.setDescription(description); // Save calculated age in tag e.setTag(TAG_NAME, calculatedAge); if (DEBUG) { const logEntry = { name: e.getTitle(), birthyear: e.getLocation(), currentYear: Math.round(currentYear), calculatedAge: Math.round(calculatedAge), } Logger.log(`${description} \n ${JSON.stringify(logEntry, null, 2)}`) } } } } } } /* -
bene-we revised this gist
Jun 9, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ This script uses Google Apps Script to access one's Google Calendar and calculat 2. Paste your calendar ID in line 9 (you can find it in the Google Calendar Settings) 3. Make sure to add the birth year of a person to the location field (or customize the script) 4. Customize the message in line 36 5. Hit run and see the messages appear in your calendar events for the current year! 6. Create a trigger to run this every year to calculate the correct age <hr> -
bene-we revised this gist
Jun 6, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,4 +13,4 @@ This script uses Google Apps Script to access one's Google Calendar and calculat <hr> <kbd><img src="https://i.imgur.com/L9Dqq6q.png"></kbd> -
bene-we revised this gist
Jun 6, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,4 +13,4 @@ This script uses Google Apps Script to access one's Google Calendar and calculat <hr> <kbd><img src="https://imgur.com/L9Dqq6q"></kbd> -
bene-we revised this gist
Jun 6, 2020 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,4 +11,6 @@ This script uses Google Apps Script to access one's Google Calendar and calculat 5. Hit run and the see the messages appear in your calendar events for the current year! 6. Create a trigger to run this every year to calculate the correct age <hr> <kbd><img src="https://i.imgur.com/7sQko0c.png"></kbd> -
bene-we revised this gist
Jun 6, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,4 +11,4 @@ This script uses Google Apps Script to access one's Google Calendar and calculat 5. Hit run and the see the messages appear in your calendar events for the current year! 6. Create a trigger to run this every year to calculate the correct age <img src="https://i.imgur.com/7sQko0c.png"> -
bene-we revised this gist
Jun 6, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,4 +11,4 @@ This script uses Google Apps Script to access one's Google Calendar and calculat 5. Hit run and the see the messages appear in your calendar events for the current year! 6. Create a trigger to run this every year to calculate the correct age [Result](https://i.imgur.com/7sQko0c.png) -
bene-we revised this gist
Jun 6, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,4 +11,4 @@ This script uses Google Apps Script to access one's Google Calendar and calculat 5. Hit run and the see the messages appear in your calendar events for the current year! 6. Create a trigger to run this every year to calculate the correct age <img src="https://imgur.com/7sQko0c" alt="result"> -
bene-we revised this gist
Jun 6, 2020 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,4 +9,6 @@ This script uses Google Apps Script to access one's Google Calendar and calculat 3. Make sure to add the birth year of a person to the location field (or customize the script) 4. Customize the message in line 36 5. Hit run and the see the messages appear in your calendar events for the current year! 6. Create a trigger to run this every year to calculate the correct age <img src="https://ibb.co/26KfcqY" alt="result"> -
bene-we created this gist
Jun 6, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ # Calculate the age of a person and write it to the event's description in your birthday calendar using Google Apps Script This script uses Google Apps Script to access one's Google Calendar and calculate the age on a person's birthday. In the best case you have a custom calendar where your birthdays are stored at. If not, uncomment line 20 and use the filter function at the bottom. ## Steps to setup everything 1. Head to https://script.google.com/home/my and create a new project. Rename the existing file Code.gs to your liking and paste the code from calculateAge.gs. 2. Paste your calendar ID in line 9 (you can find it in the Google Calendar Settings) 3. Make sure to add the birth year of a person to the location field (or customize the script) 4. Customize the message in line 36 5. Hit run and the see the messages appear in your calendar events for the current year! 6. Create a trigger to run this every year to calculate the correct age This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ const TAG_NAME = 'calculatedAge'; const FORCE_OVERWRITE = false; /* * Calculate the age of the birthday people in each year and write it in the description */ function calculateAge() { // Get Calendar 'Birthdays' var birthdayCal = CalendarApp.getCalendarById("calendarIdGoesHere"); // Select date range of current year var currentYear = (new Date()).getFullYear(); var start = new Date(currentYear + '-01-01'); var end = new Date(currentYear + '-12-31'); // Fetch events from Birthday Calendar var birthdays = birthdayCal.getEvents(start, end); // Filter Birthdays out of Default Calendar (if no specific Birthday Calendar is present) // birthdays = birthdays.filter(filterBirthdays); var calculatedAge; for (var i = 0; i < birthdays.length; i++) { e = birthdays[i]; // Year of birth is stored in the Location field of the event if (e.getLocation() !== "") { // Calculate the age if it has not been done before OR FORCE_OVERWRITE is true if ((e.getDescription() === "" && isNaN(parseInt(e.getTag(TAG_NAME)))) || FORCE_OVERWRITE) { calculatedAge = Math.round(currentYear - parseInt(e.getLocation())); // Customize the description here e.setDescription(e.getTitle() + ' wird heute ' + calculatedAge + ' Jahre!'); // Save calculated age in tag e.setTag(TAG_NAME, calculatedAge); // Logger.log(e.getTitle(), ' | ', e.getTag(TAG_NAME), ' | ', e.getDescription()); } } } } /* * Filter the birthdays out of the fetched events * Add additional filters if you don't have a specific Birthday Calendar */ function filterBirthdays(event) { // Add filter here (e.g. event.getColor === CalendarApp.Color.YELLOW) return event.isAllDayEvent(); }