创建一个if-elseif-else语句Zapier代码

问题描述

您好,我正在尝试通过if then语句检查Zappy她的JavaScript代码块中的某些输入数据。而且我目前无法使用,因为我传入了'Next Day'并且没有得到下一个日期的日期字符串。希望您有任何建议。

const inputData = {'date': '2020-08-31T22:36:27Z','delivery': 'Next Day'};

if (inputData.delivery == 'Next day') {
  const today = new Date(inputData.date)
  const tomorrow = new Date(today)
  tomorrow.setDate(tomorrow.getDate() + 1)
  const d = tomorrow
  output = {d}
} else if (inputData.delivery == 'Same Day') {
  const samedayoutput = inputData.date
  const d = samedayoutput
  output = {d}
} else {
  var d = new Date(inputData.date);
  d.setDate(d.getDate() + (1 + 7 - d.getDay()) % 7);
  output = {d}
}

解决方法

为我工作。

const inputData = {'date': '2020-08-31T22:36:27Z','delivery': 'Next Day'};

debugger;
if (inputData.delivery == 'Next Day') {
  const today = new Date(inputData.date)
  const tomorrow = new Date(today)
  tomorrow.setDate(tomorrow.getDate() + 1)
  const d = tomorrow
  output = {d}
} else if (inputData.delivery == 'Same Day') {
  const samedayoutput = inputData.date
  const d = samedayoutput
  output = {d}
} else {
  var d = new Date(inputData.date);
  d.setDate(d.getDate() + (1 + 7 - d.getDay()) % 7);
  output = {d}
}

console.log(output);