2017-01-23 2 views
1

I日間必要な数の電子メールが送信されてから経過しているかどうかを確認するには、次のスクリプトを持っている:これは、かどうかをチェックするためにうまく機能Appsスクリプトをチェックする機能

function test(){ 
    var ready = readyToSend('01/19/2017 08:00','2d'); 
} 
function readyToSend(lastDate,days){ 
    var minTimeAgo = new Date(); 
    minTimeAgo.setTime(subtract(minTimeAgo, days)); 
    var earliestDate = Utilities.formatDate(minTimeAgo, "GMT-7", "MM/dd/yyyy HH:mm"); 
    if(earliestDate > lastDate){ 
    return true; 
    } 
    return false; 
} 

日数が過ぎましたが、必要な平日の日数が経過したかどうかを知る必要があります。したがって、lastDateが木曜日で、daysが2の場合、関数は火曜日までtrueを返してはなりません。現在、2日が経過しているため、月曜日に真を返します。

週末のチェックで週末を無視するにはどうすればよいですか?

答えて

1

あなたはこれを試すことができます:あなたは(1作業週まで)過去に数日を超えてチェックする必要がある場合

function test(){ 
    var ready = readyToSend('01/19/2017 08:00','2'); 
} 
function readyToSend(lastDate,days){ 
    var minTimeAgo = new Date(new Date()-days*24*60*60*1000); // calculate the latest datetime required to meet the delay 
    lastDate = new Date(lastDate); // convert lastDate to a Date 
    var newDow = lastDate.getDay()*1 + days*1; // calculate the day of the week the new date should be 
    if(newDow > 5){ //verify that the lastDate + days does not cross a weekend 
    minTimeAgo = new Date(minTimeAgo - 2*24*3600*1000); // if so, subtract another 2 days from the latest acceptible datetime 
    } 
    if(minTimeAgo > lastDate){ 
    return true; 
    } 
    return false; 
} 

は、それが動作しません。

+0

計算のための日から 'd'を削除する必要がありますのでご注意ください。 – user2639740

関連する問題