Here is my issue from the beginning…I really need someones help….
I needed to create an event booking system for my business. I created a Google form to enter bookings into a spreadsheet and then i needed some code to automatically transfer this data to the relevant Google calendars in my account. I found someone to create this code, shared the google form/spreadsheet with them so they could create the code.
BELOW IS THE CODE THEY CREATED:
I can enter the information into the form, making submitions and they all appear on the correct date and you can see by the code it will create an all day event (if i have entered all day in one of the columns) based on the start time (startdt).
My issue is that all of a sudden my correct entries start to appear a day early in my calendar when i submit them. This happened to happen to any entries i submitted after 11pm. I am not sure what the issue is but i believe that it might be to do with timezone.
I am based in the UK which it GMT+0000, the person who made the script for me is based in India. I have read that when you change the timezone of a script, the triggers do not automatically change with it (they stay as the original timezone).
Could this be what is causing my entries to all of a sudden appear a day early in my calendar if i submit them after a certain time, even though everything in spreadsheet is correct???
I can temporarily fix the issue by editing the code to create all day event based on end time (enddt) instead of startdt but this only works for a short while.. Until 11AM possibly then i have to change the code back?? Its all very confusing.
If its a timezone issue can someone please tell me how i find out the timezone of my triggers and if they are wrong how do i edit the timezone of my triggers in the script please. I am really stuck as i need this to make bookings for my buisness without the confusion of having them appear on the wrong dates.
All of my calenders, spreadsheet, form, and script are GMT+0000
I will copy and paste my script below and embolden the all day event section i can edit to temporerily sort the problem until it changes back again if it helps?
var ss = SpreadsheetApp.getActive();
/*function onEdit(e) {
var doc = SpreadsheetApp.getActiveSheet();
setRowColors();
Browser.msgBox("Trigger it");
}*/
function onEdit(event){
var doc = SpreadsheetApp.getActiveSheet();
var r = event.source.getActiveRange();
var currentCol = r.getColumn();
// Browser.msgBox("currentCol:- "+currentCol);
if(currentCol!= 10 && currentCol!= 11 && currentCol!= 12)
{
var currentRow = r.getRow();
// Browser.msgBox("currentRow:- "+currentRow);
var v = parseInt(currentRow);
var dataRange = doc.getRange(v, 10, 1,3);
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var tom = row[0].toLowerCase();
// Browser.msgBox(tom);
var steven = row[1].toLowerCase();
var lucy = row[2].toLowerCase();
if(tom=="added" )
doc.getRange(v, 10, 1, 1).setValue("ADD");
if(steven=="added" )
doc.getRange(v, 11, 1, 1).setValue("ADD");
if(lucy=="added" )
doc.getRange(v, 12, 1, 1).setValue("ADD");
}
}
// calscript();
//Browser.msgBox("Done:-");
}
function calscript() {
//Browser.msgBox("start calscript:-");
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 2; // Number of rows to process
var dataRange = sheet.getRange(startRow, 1, sheet.getMaxRows(),35);
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var title = row[32].toString();
// Browser.msgBox(title);// First column
var desc = row[34]; // Second column
var tstart = row[2];
// Browser.msgBox(tstart);// First column
var tstop = row[3];
// Browser.msgBox(tstop);// First column
var loc = row[31];
var tom=row[9].toLowerCase();
var steven=row[10].toLowerCase();
var lucy=row[11].toLowerCase();
var day=row[4].toLowerCase();
if(tom=="add")
{
AddtoTom(day,title, tstart, tstop, {description:desc,location:loc});
dataRange.getCell(parseInt(i)+1,10).setValue('Added');
}
if(steven=="add")
{
AddtoSteven(day,title, tstart, tstop, {description:desc,location:loc});
dataRange.getCell(parseInt(i)+1,11).setValue('Added');
}
if(lucy=="add")
{
AddtoLucy(day,title, tstart, tstop, {description:desc,location:loc});
dataRange.getCell(parseInt(i)+1,12).setValue('Added');
}
//cal.createEvent(title, new Date("March 3, 2010 08:00:00"), new Date("March 3, 2010 09:00:00"), {description:desc,location:loc});
// cal.createEvent(title, tstart, tstop, {description:desc,location:loc});
}
}
function AddtoTom(day,title,startdt,enddt,desc)
{
var cal = CalendarApp.openByName("Tom");
if(day=="all day")
**cal.createAllDayEvent(title, **startdt,** desc)**
else
cal.createEvent(title, startdt, enddt, desc);
}
function AddtoSteven(day,title,startdt,enddt,desc)
{
var cal = CalendarApp.openByName("Steven");
if(day=="all day")
**cal.createAllDayEvent(title, **startdt**, desc)**
else
cal.createEvent(title, startdt, enddt, desc);
}
function AddtoLucy(day,title,startdt,enddt,desc)
{
var cal = CalendarApp.openByName("Lucy");
if(day=="all day")
**cal.createAllDayEvent(title, **startdt**, desc)**
else
cal.createEvent(title, startdt, enddt, desc);
}
function onOpen() {
// Browser.msgBox('start');// First column
var menuEntries = [];
menuEntries.push({name: "Add To Calendar", functionName: "calscript"});
ss.addMenu("Main Menu", menuEntries);
// Browser.msgBox('end');// First column
}
function onInstall() {
onOpen();
}
function onFormSubmit()
{
}
function configure() {
// Browser.msgBox('trigger');// First column
ScriptApp.newTrigger("calscript").timeBased().everyMinutes(1).create();
//Browser.msgBox('trigger ends');// First column
}
OK i was being an idiot i think……. It turns out it wasn’t a really a script issue it was a daylight savings issue as the only results that were a day early appeared after the 1st April 2013 I had the timezone for my calenders, form/spreadsheet and script set to GMT+0000. I simply reset them all to ‘GMT+0000 no daylight savings’ and this seems to fix the issue. I recommend this to anybody having a similar date issue where the dates are pushed back a day or the times are pushed back an hour.