I copied some code from this website so I can import a google calendar into google sheets. I am not a programmer, I know just enough to be dangerous. I am wondering if there is a line(s) of code that can be added to the script below that will account for Daylight Savings Time.
I live in the Central Time Zone (Missouri). My computer is set to Central Time Zone-Chicago. Now that DST is here, all the times that are imported from Google Calendar into Google Sheets are 1 hour behind what they actually show in Google Calendar. Is there a line(s) of code that can be added to this script to account for DST and pull in the correct times? Any help is greatly appreciated. Thanks, Eric
function importGoogleCalendar() {
var sheet = SpreadsheetApp.getActiveSheet();
var calendarId = sheet.getRange('B1').getValue().toString();
var calendar = CalendarApp.getCalendarById(calendarId);
// Set filters
var startDate = sheet.getRange('B2').getValue();
var endDate = sheet.getRange('B3').getValue();
var searchText = '';
// Print header
var header = [["Title", "Location", "Start", "End", "Duration"]];
var range = sheet.getRange("A6:E6");
range.setValues(header);
range.setFontWeight("bold")
// Get events based on filters
var events = (searchText == '') ? calendar.getEvents(startDate, endDate) : calendar.getEvents(startDate, endDate, {search: searchText})
// Display events
for (var i=0; i<events.length; i++) {
var row = i+7;
var details = [[events[i].getTitle(), events[i].getLocation(), events[i].getStartTime(), events[i].getEndTime(), '']];
range = sheet.getRange(row,1,1,5);
range.setValues(details);
/ Format the Start and End columns
var cell = sheet.getRange(row, 3);
cell.setNumberFormat('mm/dd/yyyy hh:mm');
cell = sheet.getRange(row, 4);
cell.setNumberFormat('mm/dd/yyyy hh:mm');
// Fill the Duration column
cell = sheet.getRange(row, 5);
cell.setFormula('=(HOUR(D' + row + ')+(MINUTE(D' +row+ ')/60))-(HOUR(C' +row+ ')+(MINUTE(C' +row+ ')/60))');
cell.setNumberFormat('0.00');
}
}
Check your script timezone.
To do that, go to settings in your script editor (select the gear on the left hand side) and active the third checkbox. Return to the script editor and edit appsscript.json. Change as needed the time zone (America/Chicago).