From 9fec9bca998ced75d9c0b9a8b53a4f5cb2684ec8 Mon Sep 17 00:00:00 2001 From: Cosmo Date: Thu, 23 Apr 2026 09:29:21 +0000 Subject: [PATCH] fix(calendar): all-day end.date must be next day, clear opposite field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Google Calendar API rejects all-day events where start.date == end.date (end is exclusive). POST/PUT were sending the same date for both, producing Invalid start time when toggling Весь день on edit. - Added nextDayISO helper (UTC-safe +1d arithmetic) - all-day: start = { date }, end = { date: nextDay, dateTime: null } - timed: also explicitly nulls start.date/end.date so patching a timed-only event over a previously all-day one doesnt leave stale date fields that also trigger Invalid start time --- app/api/calendar/route.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/api/calendar/route.ts b/app/api/calendar/route.ts index f6c8e3f..5f64bec 100644 --- a/app/api/calendar/route.ts +++ b/app/api/calendar/route.ts @@ -4,6 +4,12 @@ import { google } from 'googleapis' import * as fs from 'fs' import * as path from 'path' +function nextDayISO(date: string): string { + const d = new Date(`${date}T00:00:00Z`) + d.setUTCDate(d.getUTCDate() + 1) + return d.toISOString().slice(0, 10) +} + function getAuth(readonly = true) { const scopes = readonly ? ['https://www.googleapis.com/auth/calendar.readonly'] @@ -134,11 +140,11 @@ export async function POST(req: Request) { let start: any, end: any if (allDay) { - start = { date } - end = { date } + start = { date, dateTime: null } + end = { date: nextDayISO(date), dateTime: null } } else { - start = { dateTime: `${date}T${startTime}:00`, timeZone: 'Europe/Moscow' } - end = { dateTime: `${date}T${endTime}:00`, timeZone: 'Europe/Moscow' } + start = { dateTime: `${date}T${startTime}:00`, timeZone: 'Europe/Moscow', date: null } + end = { dateTime: `${date}T${endTime}:00`, timeZone: 'Europe/Moscow', date: null } } try { @@ -181,11 +187,11 @@ export async function PUT(req: Request) { let start: any, end: any if (allDay) { - start = { date } - end = { date } + start = { date, dateTime: null } + end = { date: nextDayISO(date), dateTime: null } } else { - start = { dateTime: `${date}T${startTime}:00`, timeZone: 'Europe/Moscow' } - end = { dateTime: `${date}T${endTime}:00`, timeZone: 'Europe/Moscow' } + start = { dateTime: `${date}T${startTime}:00`, timeZone: 'Europe/Moscow', date: null } + end = { dateTime: `${date}T${endTime}:00`, timeZone: 'Europe/Moscow', date: null } } try {