0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[GAS] 今日が土日・祝日であるかを判定する

Posted at
// 今日が休日(土日、祝日)か判定する関数
function todayIsHoliday(){
  //実行した当日の日付情報を取得する
  let today = new Date();
  //今日の曜日(0:日曜~6:土曜)を取得し、土日と判定された場合はtrueを返す
  let weekInt = today.getDay();
  
  //祝日を判定するため、日本の祝日を公開しているGoogleカレンダーと接続する 
  let calendarId = "ja.japanese#holiday@group.v.calendar.google.com"; 
  let calendar = CalendarApp.getCalendarById(calendarId); //翌日にイベントが設定されているか取得し、イベントが有る場合はtrueを返す 
  let todayEvents = calendar.getEventsForDay(today); 

  if(weekInt == 0 || 6 == weekInt){ 
    return true; 
  } 
  else if(todayEvents.length > 0){
    return true;
  }
  //土日、祝日のいずれでもない場合は、休日ではないとしてfalseを返す
  return false;
}

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?