I'm seeing weird inconsistencies and discrepancies when writing constructed dates into google sheets, they do not always transform into date object once the sheet values are retrieved at a later time.
By constructed dates I mean they are created by sticking together smaller day, month and time strings into a single string "01/02/1991 00:00:00". They are then written into the sheet using .setValues(). And then after work is done, I retrieve the array using .getValues() to only find that once in a while, those dates are retrieved as string values, with the vast majority being date objects.
Originally, I had not padded out the values, but now I add (inside the string) leading 0s. This has fixed issues in some placed but not all places.
Here are some excerpts of how I create the array that gets written eventually using .setValues
var date = data_range[i][header_date].toString()
var day = parseInt(date.slice(6,8),10)
var month = parseInt(date.slice(4,6),10)
var year = parseInt(date.slice(0,4),10)
organised_data[organised_data_index].data = organised_data[organised_data_index].data.concat(data_range[i].slice(header_data, header_data+int_entries))
var datetime_array = []
for (var k = 0; k< minutes_array.length; k++){
datetime_array[k] = pad(day,2) + "/" + pad(month,2) + "/"+ year + " " + pad(parseInt(minutes_array[k]/60),2)+ ":" + pad((minutes_array[k] % 60),2) + ":00"
}
organised_data[organised_data_index].datestamp = organised_data[organised_data_index].datestamp.concat(datetime_array)
Here is what I'm seeing in the debug: https://i.imgur.com/OTT296s.png
Here is what I'm seeing in the sheet itself: https://i.imgur.com/hDvqGP3.png
Has anyone else faced these issues, am I doing something wrong?
So for anyone asking why I've written my dates like this, it's because the script will be passed around between countries, and I've noticed that the localisation changes and therefore using date objects inside the javascript gets really screwey. I've opted to create the string itself since the data is time zone agnostic. Could we treat that side of my problem as a constraint?
Thanks guys, this is killing me.