64
55

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】休日・祝日を判定する関数

Last updated at Posted at 2017-01-22

休日・祝日を判定する関数

GASのスクリプトを平日だけ動かしたかったため、判定する関数を作成。

function isHoliday(){
  var today = new Date();

  //土日か判定
  var weekInt = today.getDay();
  if(weekInt <= 0 || 6 <= weekInt){
    return true;
  }
  
  //祝日か判定
  var calendarId = "ja.japanese#holiday@group.v.calendar.google.com";
  var calendar = CalendarApp.getCalendarById(calendarId);
  var todayEvents = calendar.getEventsForDay(today);
  if(todayEvents.length > 0){
    return true;
  }
  
  return false;
}

タイムゾーンが JST にならない場合は

application.json にて TimeZone を変更すればよろしいかと思います。

参考: GASの新しいエディタでタイムゾーンを変更する

64
55
2

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
64
55

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?