Reputation: 37
I am writing a Script, which I want to NOT run during an interval of the day (since I have other scripts operating on the sheet during that time frame). I want to insert one line of code at the beginning of my function which will just perform a quick check whether the current time of the day is in that time interval or not, but I am unable to do so. Here is the code: //This the code block which will prevent night time running
var d = new Date();
var hours = d.getHours(); if(hours.toString().length==1){var hours = '0'+hours;}
Logger.log(hours);
if ((hours >= 1) || (hours <= 6))
return;
// Basically making the code not run at night time
But this is giving errors. The time is coming in UTC even when explicitly time zone is mentioned. Can someone please help?
Upvotes: 1
Views: 3381
Reputation: 6062
The reason you are not receiving the expected result is due to the fact that the appsscript.json
manifest file is the one who is holding the information regarding the timezone for your script.
Moreover, the getHours
method as described here does not expect any parameters, so the timezone
mentioned there won't do much.
To see the manifest file, you will have to Project Settings in the script project and then tick the box which says Show "appsscript.json" manifest file in editor. Afterwards, edit the file such that the timezone of the script is timeZone: 'Asia/Kolkata'
.
Upvotes: 3