Google Apps脚本可在特定日期停止触发 [英] Google apps script to stop the trigger on specific days
本文介绍了Google Apps脚本可在特定日期停止触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个脚本功能,我创建了一个每小时运行一次的触发器
I have a script function, and I created a trigger to run every hour
我需要在特定的日期和时间停止触发 例如,我不想从星期五下午5点到星期六晚上10点运行它
I need to stop that trigger at specific day and times for example I don't want to run it from Friday 5pm until Saturday 10pm
我找到了可以按天停止它的功能
I found a function to stop it by day
//Skip week-end
var day = new Date();
if (day.getDay()>5 || day.getDay()==0) {
return;
}
但是我不知道如何从周五下午5点到周六晚上10点做更具体的操作
but I don't know how to accomplish to be more specific from Friday 5pm until Saturday 10pm to don't run it
有什么帮助吗?
推荐答案
如果日期和时间落在指定的时间段内,您可能希望在触发器函数中包含一个检查以跳过处理.
You might want to include a check inside the trigger function to skip processing if the date and time fall in the specified period.
function shouldRunTrigger() {
var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
var date = new Date();
var day = days[date.getDay()];
var hours = date.getHours();
if ((day === "Fri" && hours >= 17) || (day === "Sat" && hours <= 22)) {
return false;
}
return true;
}
function myTrigger() {
if (!shouldRunTrigger()) return;
// trigger code here
}
这篇关于Google Apps脚本可在特定日期停止触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文