【发布时间】:2022-01-10 03:08:26
【问题描述】:
如果该值不在一行中,我正在尝试设置一个输入值。我可以获取行的值并设置值。
当我询问输入是否在行中时,出现了我的问题。这是我的脚本:
//Auxiliar Funtion
function is_in_array(array,value) {
is_in = false
Logger.log('This is the value: ' + value)
for (i = 0; i < array.length; i++) {
Logger.log('This is i: ' + array[i])
if (value == array[i]) {
is_in=true;
Logger.log('I was here!')
}
}
return is_in
}
//Main
function rm(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ws = ss.getActiveSheet();
var fecha = ws.getRange(5,9).getValue();
//Reviso si existe la fecha
ws = ss.getSheetByName(tipo);
numCols = ws.getLastColumn();
fechas = ws.getRange(1,4,1,numCols).getValues()[0];
Logger.log('Fecha :' + fecha);
Logger.log('Fechas: ' + fechas);
is_in_result = is_in_array(fechas, fecha)
Logger.log('Functions result: ' + is_in_result)
//Logger.log(ArrayUtils.contains( fechas, fecha ))
if (is_in_result==true) {
Logger.log('If statement')
return True
} else {
Logger.log('Else Statement')
//Se añade la fecha
ws.getRange(1,numCols+1).setValue(fecha)
}
}
这是日志:
Registros de Cloud
9 ene 2022, 23:51:54 Información Fecha :Thu Sep 09 2021 03:00:00 GMT-0400 (hora de verano oriental)
9 ene 2022, 23:51:54 Información Fechas: Thu Sep 09 2021 03:00:00 GMT-0400 (hora de verano oriental),Fri Oct 15 2021 03:00:00 GMT-0400 (hora de verano oriental),Wed Dec 08 2021 03:00:00 GMT-0500 (hora estándar oriental),,,
9 ene 2022, 23:51:54 Información This is the value: Thu Sep 09 2021 03:00:00 GMT-0400 (hora de verano oriental)
9 ene 2022, 23:51:54 Información This is i: Thu Sep 09 2021 03:00:00 GMT-0400 (hora de verano oriental)
9 ene 2022, 23:51:54 Información This is i: Fri Oct 15 2021 03:00:00 GMT-0400 (hora de verano oriental)
9 ene 2022, 23:51:54 Información This is i: Wed Dec 08 2021 03:00:00 GMT-0500 (hora estándar oriental)
9 ene 2022, 23:51:54 Información This is i:
9 ene 2022, 23:51:54 Información This is i:
9 ene 2022, 23:51:54 Información This is i:
9 ene 2022, 23:51:54 Información Functions result: false
9 ene 2022, 23:51:54 Información Else Statement
Fecha 在 Fechas 中,所以函数结果必须为 true,但返回 false :(
我的错误在哪里? 或者,有更简单的方法来获得相同的结果? 也许它不起作用,因为我正在比较两个日期,我不知道......
有些东西是西班牙语,抱歉
【问题讨论】:
标签: javascript datetime google-apps-script date-comparison