Skip to content

Commit

Permalink
Handle events with untimed end date
Browse files Browse the repository at this point in the history
  • Loading branch information
htadashi committed Jul 15, 2024
1 parent 40e995d commit 12be42a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions modules/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function isAllDayEvent(dateString) {
const allDayFormat = /^\d{8}$/;
return allDayFormat.test(dateString);
}
10 changes: 9 additions & 1 deletion service_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { buildRequestOpenAI, parseResponseOpenAI } from "./modules/openai.js";
import { buildRequestGemini, parseResponseGemini } from "./modules/gemini.js";
import { GET_EVENT_PARAMETERS } from "./modules/prompts.js";

import { isAllDayEvent } from "./modules/util.js";
chrome.action.onClicked.addListener(() => {
chrome.runtime.openOptionsPage();
});
Expand Down Expand Up @@ -62,7 +63,14 @@ chrome.contextMenus.onClicked.addListener((info, tab) => {

// Format the dates
const startDate = event.start_date;
const endDate = event.end_date;
// For untimed events the end date is exclusive, so the end date should be the next day.
let endDate;
if (isAllDayEvent(event.end_date)) {
endDate = new Date(event.end_date.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3'));
endDate.setDate(endDate.getDate() + 1);
event.end_date = endDate.toISOString().split('T')[0].replace(/-/g, '');
}
endDate = event.end_date;

// URL encode the event details
const title = encodeURIComponent(event.title);
Expand Down

0 comments on commit 12be42a

Please sign in to comment.