Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function syncFromCalendar() {
// Map spreadsheet column titles to indices
const idxMap = Util.createIdxMap(data[Util.TITLE_ROW]);
const idIdx = idxMap.indexOf('id');
const startTimeIdx = idxMap.indexOf('starttime');

// Verify title row has all required fields
const includeAllDay = userSettings.all_day_events === AllDayValue.use_column;
Expand All @@ -77,14 +78,14 @@ function syncFromCalendar() {
}

// Get all of the event IDs from the sheet
const sheetEventIds = data.map(row => row[idIdx]);
const sheetEventIds = data.map(row => Util.generateUniqueId(row[idIdx],row[startTimeIdx]));

// Loop through calendar events and update or add to sheet data
let eventFound = new Array(data.length);
for (let calEvent of calEvents) {
const calEventId = calEvent.getId();

let rowIdx = sheetEventIds.indexOf(calEventId);
const calEventStartTime = calEvent.getStartTime();
let rowIdx = sheetEventIds.indexOf(Util.generateUniqueId(calEventId,calEventStartTime));
if (rowIdx < Util.FIRST_DATA_ROW) {
// Event not found, create it
rowIdx = data.length;
Expand Down
10 changes: 10 additions & 0 deletions Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,14 @@ const TITLE_ROW_MAP: Map<GenericEventKey, string> = new Map([
static isValidDate(d: string) {
return isNaN(Date.parse(d)) === false;
}

static generateUniqueId(id: string, startTime: string){
const dateFormat = "yyyyMMddHHmmss";
if(Util.isValidDate(startTime)){
return Utilities.formatDate(startTime, "GMT", dateFormat) + id
}else {
return id
}
}

}