Skip to content

Instantly share code, notes, and snippets.

@fromkk
Created February 25, 2021 02:59
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 fromkk/bc5f5722f2ea53f81729eb2408e9d14b to your computer and use it in GitHub Desktop.
Save fromkk/bc5f5722f2ea53f81729eb2408e9d14b to your computer and use it in GitHub Desktop.
当日のカレンダーをサマリをメールで送信する
function main() {
const calendarId = "YOUR_GMAIL_ADDRESS";
const calendar = CalendarApp.getCalendarById(calendarId);
const now = new Date();
const weekday = now.getDay();
const events = calendar.getEventsForDay(now);
var horidayCalendar = CalendarApp.getCalendarById('ja.japanese#holiday@group.v.calendar.google.com');
if (horidayCalendar.getEventsForDay(now, {max: 1}).length > 0) {
return;
}
// 休日は実行させない
if (weekday == 0 || weekday == 6) {
return;
}
var title = `${day(now)}の会議の予定`;
var body = "";
if (events.length == 0) {
body = "今日は会議の予定はありません";
} else {
body += "今日の会議の予定は\n";
events.forEach((event) => {
body += `${getTime(event.getStartTime())} - ${getTime(event.getEndTime())}\n`;
});
body += `の${events.length}件です`;
}
MailApp.sendEmail({
to: "TO_EMAIL_ADDRESS",
subject: title,
body: body
});
}
/**
* yyyy/MM/ddにして返す
*
* @param {Date} date
*/
function day(date) {
const year = date.getFullYear();
const month = ('00' + (date.getMonth() + 1)).slice(-2);
const day = ('00' + date.getDate()).slice(-2);
return `${year}/${month}/${day}`
}
/**
* カレンダーの日付
*
* @param {Date} date
*/
function getTime(date) {
const hours = ('00' + date.getHours()).slice(-2);
const minutes = ('00' + date.getMinutes()).slice(-2);
return `${hours}:${minutes}`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment