I've been facing an extrange issue with google scripts. Bellow the easy-to-understand snippet:
//https://stackoverflow.com/a/7390612/2873381
function typeOf(obj) {
return {}.toString.call(obj).split(' ')[1].slice(0, -1).toLowerCase();
}
function run(working_day){
if (!working_day){
working_day = new Date();
}
console.log("working_day");
console.log(typeOf(working_day));
console.log(working_day);
var timeZone = Session.getTimeZone();
var curr_day = Utilities.formatDate(working_day, timeZone, "F");
var curr_hour = Utilities.formatDate(working_day, timeZone, "H");
console.log(curr_day);
console.log(curr_hour);
}
This snippet get now
if no working_day
is provided. Once it has a valid instance of Date
it tries to get week-day and current-hour using Utilities
handy functions.
If I run this snippet manually from Editor, there's no problem, output is the expected .
However, If I set a crontab execution, say every hour, this code raises an error
The weirdest point here is the unexpected javaobject
value, I don't know why working_day
gets this instance type....
Can you help me? Thanks