7
12

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 5 years have passed since last update.

[GAS]営業日判断スクリプト

Last updated at Posted at 2018-11-13

###はじめに
営業日のみ日報を送りたかったので作成しました。

上から土日判別、祝日判別を組んでいます。
条件に合致したら、returnで終了してます。
祝日はGoogle Calendarから持ってきています。


//営業日を判別するスクリプト
//土日祝日は”false”,平日は”true”を返す
//祝日はGoogleカレンダーから取得
//目的:土日祝日動いていないアカウントにはメールを送らない

function checkHoliday() {
  
  var moment = Moment.moment();
  var today = moment.format("YYYY/MM/DD");
  var Weekday = moment.format("dddd");
  
  //HACK:elseifのほうが自然?
  if(Weekday == "Sunday" || Weekday == "Saturday"){
    return false;
  }
  
  var holiday = CalendarApp.getCalendarById("ja.japanese#holiday@group.v.calendar.google.com");//祝日カレンダー
  var date = moment.toDate();//getEventsForDayでDATE形式が必要なため
  var holidayEvent = holiday.getEventsForDay(date);
  
  if(holidayEvent.length > 0){//Googleカレンダーから祝日の有無を確認
    return false;
  }
  return true; 
}

Logger.log(checkHoliday());
7
12
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
7
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?