Created
February 25, 2021 02:59
-
-
Save fromkk/bc5f5722f2ea53f81729eb2408e9d14b to your computer and use it in GitHub Desktop.
当日のカレンダーをサマリをメールで送信する
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 characters
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#[email protected]'); | |
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