Skip to content

Instantly share code, notes, and snippets.

@suzuki-kei
Created April 29, 2020 13:44
Show Gist options
  • Save suzuki-kei/9f89ea02611108975ea2bd1ebd5d2cc3 to your computer and use it in GitHub Desktop.
Save suzuki-kei/9f89ea02611108975ea2bd1ebd5d2cc3 to your computer and use it in GitHub Desktop.
休業日を判定する Google Apps Script
/**
* 指定された日付が休業日であるか判定する.
*
* @param {Date} date
* 判定対象の日付.
*
* @return {Object}
* 休業日の場合は Truthy な値.
* 休業日ではない場合は Falsy な値.
*/
function isHoliday(date) {
// 日本の祝日.
let calendarId = "ja.japanese#[email protected]"
let calendar = CalendarApp.getCalendarById(calendarId)
let events = calendar.getEventsForDay(date)
if (events.length !== 0) {
return events[0].getTitle()
}
// 年末年始 (12/28 - 1/3) は会社休業日.
let monthAndDate = (date.getMonth() + 1) * 100 + date.getDate()
if (1228 <= monthAndDate || monthAndDate <= 103) {
return "会社休業日"
}
// 土曜日, 日曜日は休業日.
if (date.getDay() === 0) {
return "日曜日"
}
if (date.getDay() === 6) {
return "土曜日"
}
// それ以外は営業日.
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment