fix(calendar): all-day end.date must be next day, clear opposite field
All checks were successful
Deploy / deploy (push) Successful in 2m50s

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
This commit is contained in:
Cosmo
2026-04-23 09:29:21 +00:00
parent dc5c9b3673
commit 9fec9bca99

View File

@@ -4,6 +4,12 @@ import { google } from 'googleapis'
import * as fs from 'fs' import * as fs from 'fs'
import * as path from 'path' 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) { function getAuth(readonly = true) {
const scopes = readonly const scopes = readonly
? ['https://www.googleapis.com/auth/calendar.readonly'] ? ['https://www.googleapis.com/auth/calendar.readonly']
@@ -134,11 +140,11 @@ export async function POST(req: Request) {
let start: any, end: any let start: any, end: any
if (allDay) { if (allDay) {
start = { date } start = { date, dateTime: null }
end = { date } end = { date: nextDayISO(date), dateTime: null }
} else { } else {
start = { dateTime: `${date}T${startTime}:00`, timeZone: 'Europe/Moscow' } start = { dateTime: `${date}T${startTime}:00`, timeZone: 'Europe/Moscow', date: null }
end = { dateTime: `${date}T${endTime}:00`, timeZone: 'Europe/Moscow' } end = { dateTime: `${date}T${endTime}:00`, timeZone: 'Europe/Moscow', date: null }
} }
try { try {
@@ -181,11 +187,11 @@ export async function PUT(req: Request) {
let start: any, end: any let start: any, end: any
if (allDay) { if (allDay) {
start = { date } start = { date, dateTime: null }
end = { date } end = { date: nextDayISO(date), dateTime: null }
} else { } else {
start = { dateTime: `${date}T${startTime}:00`, timeZone: 'Europe/Moscow' } start = { dateTime: `${date}T${startTime}:00`, timeZone: 'Europe/Moscow', date: null }
end = { dateTime: `${date}T${endTime}:00`, timeZone: 'Europe/Moscow' } end = { dateTime: `${date}T${endTime}:00`, timeZone: 'Europe/Moscow', date: null }
} }
try { try {