I am running an repeated import of data including a duration value from csv. The duration value is after import read by Google Script and processed. Afterwards the sheet is cleared and expecting new import. The duration value comes sometimes in as time object and is processed correctly. More often the script crashes because instead of timeobject or string duration is a number, like: 0.04758265 ... and when asked for .getHours() there is no.
Question 1: How do I programatically format the column to duration format after clear?
Question 2: How to convert the number to something processable by .getHours() method?
EDIT: Code as requested.
//import snippet
var file = DriveApp.getFilesByName(fileName);
mysheet.getRange(startRow,1,1000,30).clearContent();
var csvFile = file.getBlob().getDataAsString();
var csvData = CSVToArray(csvFile,"/");
var rowi = 0;
for ( var i=3, lenCsv=csvData.length; i<lenCsv; i++ ) {
if (csvData[i][0].length > 0) {
if (csvData[i][8].indexOf("*")==-1) {
csvData[i][8] = "";
}
mysheet.getRange((rowi+startRow), startCol, 1, csvData[i].length).setValues(new Array(csvData[i]));
rowi++;
}
}
//snippet of function where i get error
var durArr = mysheet.getRange("L4:L997").getValues();
var noHours;
for (var i=0;i<durArr.length;i++) {
if (durArr[i][0] != '') {
var valType = typeof durArr[i][0];
//the bellow line breaks the code
if (durArr[i][0].getHours() == 0) {noHours+=1}
if (noHours<100) {
return true;
}