Last active
June 13, 2020 23:26
-
-
Save Adrian-Samuel/644cba1a1dd1ad92d8e1df4d613d0032 to your computer and use it in GitHub Desktop.
This file contains 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 characters
function birthdayMessage() { | |
const sheet = SpreadsheetApp.openById("someID"); | |
const [headers, ...birthdays] = sheet.getDataRange().getValues(); | |
// removing rows without dates | |
const cleanedList = birthdays.filter(([,date]) => date != "") | |
const todaysBirthdays = cleanedList.reduce((matchedBirthdays, currentBirthday) => { | |
const time = 1000 * 60 * 60 * 24 | |
const [name, date] = currentBirthday | |
const birthdayMilliseconds = new Date(date).getTime() | |
const currentDate = new Date().getTime() | |
if(currentDate >= birthdayMilliseconds && currentDate < (birthdayMilliseconds + time)){ | |
return [...matchedBirthdays, [name, new Date(date).toLocaleDateString()]] | |
} | |
return matchedBirthdays | |
},[]) | |
if(todaysBirthdays.length === 0) return | |
const html = ` | |
<!DOCTYPE html> | |
<html lang="en"> | |
<body> | |
<h1>Birthday List</h1> | |
<ol> | |
${todaysBirthdays.reduce((htmlString, [name, birthday]) => { | |
return htmlString += | |
`<li> The celebrant's name is <span> ${name} </span> and their birthday is today: ${birthday} </li>` | |
}, '')} | |
</ol> | |
</body> | |
</html> | |
` | |
GmailApp.sendEmail(["somebody@gmail.com", "somebody@gmail.com""], "Today's Church Birthday List", "", { | |
htmlBody: html | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment