はじめに
GoogleAppsScriptではカレンダー連携が容易なことから、営業時間、はたまた営業日かどうかで処理をするというのは非常に有益な処理です。
以下のプログラムをコピペで実装すれば判定できます。
詳細
function isBusinessHours() {
// hhで東京タイムゾーンの時間を取得
var nowHour = Utilities.formatDate(new Date(), "Asia/Tokyo","HH").slice(-2);
// 17時~翌8時までは閉店です
if ("17" <= nowHour || nowHour <= "08") {
return false;
} else {
return true;
}
}
function isBusinessDay(){
var tmpToday = Utilities.formatDate(new Date(), "Asia/Tokyo","E");
if (tmpToday === "Sat" ||
tmpToday === "Sun") {
return false;
} else {
return true;
}
}
function isHoliday(){
var calendar = CalendarApp.getCalendarById("ja.japanese#holiday@group.v.calendar.google.com");
var todayEvents = calendar.getEventsForDay(new Date());
if(todayEvents.length > 0){
return true;
}
return false;
}
function test(){
if ( isBusinessDay() && isBusinessHours()) {
//営業日の処理を実装
} else if (isHoliday()) {
//祝日の処理を実装
} else
//非営業日の処理を実装
}
}
という具合に、時間判定、曜日判定を組み合わせれば営業日処理ができます。