diff --git a/helpers/date.ts b/helpers/date.ts index 30c2e5b..43014ad 100644 --- a/helpers/date.ts +++ b/helpers/date.ts @@ -80,3 +80,7 @@ export function nowInTz(timezone = 'Europe/Berlin'): Date { const now = new Date() return utcToZonedTime(now, timezone) } + +export function getNextDay(date: Date) { + return addDays(date, 1) +} diff --git a/lib/googlecalendar.ts b/lib/googlecalendar.ts index 4de4b81..6d49db7 100644 --- a/lib/googlecalendar.ts +++ b/lib/googlecalendar.ts @@ -1,7 +1,7 @@ import { google } from 'googleapis' import { getBaseURL } from '../helpers/url' import { Booking } from '../db/booking' -import { getDays } from '../helpers/date' +import { getDays, getNextDay, dateFormatBackend } from '../helpers/date' import { log } from '../helpers/log' const calendarId = process.env.GOOGLE_CALENDAR_ID @@ -66,18 +66,19 @@ function getDescription(booking: Booking): string { } export async function createCalendarEvent(booking: Booking): Promise { - const response = await calendar.events.insert( - { - calendarId, - requestBody: { - summary: getSummary(booking), - description: getDescription(booking), - start: { date: booking.startDate }, - end: { date: booking.endDate }, - }, - }, - {} + const exclusiveEndDate = dateFormatBackend( + getNextDay(new Date(booking.endDate)) ) + const data = { + calendarId, + requestBody: { + summary: getSummary(booking), + description: getDescription(booking), + start: { date: booking.startDate }, + end: { date: exclusiveEndDate }, + }, + } + const response = await calendar.events.insert(data, {}) booking.calendarEventId = response.data.id