Skip to content

Instantly share code, notes, and snippets.

@Adrian-Samuel
Last active June 13, 2020 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Adrian-Samuel/644cba1a1dd1ad92d8e1df4d613d0032 to your computer and use it in GitHub Desktop.
Save Adrian-Samuel/644cba1a1dd1ad92d8e1df4d613d0032 to your computer and use it in GitHub Desktop.
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