Currently, I want to run my google app script at exact time. I have already do some reading about this problem and I decide to follow the solution in this post It's possible run Google Sheets script Exact Time Everyday?.

However, every time the time trigger only work only once. It will display error for the second time trigger. I google about this problem and most of them state that is google v8 bug.( https://issuetracker.google.com/issues/150756612).

So, I'm decide to downgrade my code to ES5 since that is the only solution from the post( https://issuetracker.google.com/issues/150756612). But, I'm facing a problem about changing the spread operator(...) to ES5

Here is my code:

function runTrigger(hours,minutes) {
  
  var today_D=new Date();
  var year=today_D.getFullYear();
  var month=today_D.getMonth();
  var day=today_D.getDate();
  
  day=day+1; 
  
  var pars=[year,month,day,hours,minutes];
  
  var schedule_date=new Date(...pars);
  var hours_reamain=Math.abs(schedule_date - today_D)/36e5;
  
  ScriptApp.newTrigger("testFunction")
   .timeBased()
   .after(hours_reamain*60*60*1000)
   .create()  
}

function deleteTrigger() {
  var triggers=ScriptApp.getProjectTriggers();
  
  var ssId="1d5P4ohgSLtOzuInxq1IYQUsB4GybeYhth5Gj21RI3rA";
  var ss=SpreadsheetApp.openById(ssId);
  
  for(var i=0 ; i< triggers.length ; i++) {
    ss.appendRow([new Date() ,JSON.stringify(triggers[i]), JSON.stringify(triggers[i].getHandlerFunction()) , JSON.stringify(triggers[i].getEventType()) , JSON.stringify(triggers[i].getTriggerSource())])
    if(triggers[i].getHandlerFunction() === "testFunction") {
      ScriptApp.deleteTrigger(triggers[i]);
    }
  }
}

function setTrigger() { 
    deleteTrigger();
    runTrigger(1,35);
}

function testFunction() {
  //some code at here
  setTrigger();
}

Can anybody teach me how can I change the ...(spread operator) to ES5

推荐答案

It's a javascript Date() constructor

 var schedule_date=new Date(year,month,day,hours,minutes);

Date() constructor

Javascript相关问答推荐

你怎么看啦啦队的回应?

如何在ASP.NET JavaScript中使用Google Charts API仅对绘制为负方向的条形图移动堆叠条形图标签位置

如何从HTML对话框中检索单选项组的值?

我怎么在JS里连续加2个骰子的和呢?

使用领域Web SDK的Vite+Vue应用程序中的Web程序集(WASM)错误

更新动态数据中对象或数组中的所有值字符串

第三方包不需要NODE_MODULES文件夹就可以工作吗?

警告框不显示包含HTML输入字段的总和

如何根据输入数量正确显示alert ?

用另一个带有类名的div包装元素

P5.js中矩形内的圆弧

React数组查找不读取变量

使用静态函数保存 node 前的钩子

找不到处于状态的联系人

使用Java脚本筛选数组中最接近值最小的所有项

此上下文在JavaScript中

V-如果使用数组[vue3]中的布尔结果

Svelte:数组内的值绑定不起作用

在p5.js中,2D数组位图读取器不支持同一行中的重复 colored颜色

用对象填充数组的快速方法