{"record":{"id":"4d9060f0dc77e926","repo":"calcom/cal.diy","slug":"invalid-time-range-given-check-the-starttime-a","errorCode":null,"errorMessage":"Invalid time range given - check the 'startTime' and 'endTime' query parameters.","messagePattern":"Invalid time range given - check the 'startTime' and 'endTime' query parameters\\.","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apps/api/v2/src/modules/slots/slots-2024-04-15/controllers/slots.controller.ts","lineNumber":217,"sourceCode":"\n      const { slots } = await this.slotsOutputService.getOutputSlots(\n        availableSlots,\n        query.duration,\n        query.eventTypeId,\n        query.slotFormat,\n        query.timeZone\n      );\n\n      return {\n        data: {\n          slots,\n        },\n        status: SUCCESS_STATUS,\n      };\n    } catch (error) {\n      if (error instanceof Error) {\n        if (error.message.includes(\"Invalid time range given\")) {\n          throw new BadRequestException(\n            \"Invalid time range given - check the 'startTime' and 'endTime' query parameters.\"\n          );\n        }\n\n        if (TRPC_ERROR_MAP[error.message as keyof typeof TRPC_ERROR_CODE]) {\n          throw new TRPCError({ code: error.message as TRPCErrorCode });\n        }\n      }\n\n      throw error;\n    }\n  }\n}\n","sourceCodeStart":199,"sourceCodeEnd":231,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/apps/api/v2/src/modules/slots/slots-2024-04-15/controllers/slots.controller.ts#L199-L231","documentation":"BadRequestException (HTTP 400) thrown by the slots controller when the underlying getAvailableSlots call throws an Error whose message contains the substring 'Invalid time range given'. The controller inspects the upstream error text and rewraps it as a 400 pointing the caller at the startTime/endTime query params. The original throw lives in the slots/getSlots domain logic and signals that the requested window is empty, inverted, or otherwise malformed.","triggerScenarios":"GET /v2/slots/2024-04-15 with startTime >= endTime, startTime/endTime outside allowed bounds, endTime in the past, or a window the engine considers degenerate (zero or negative duration after timezone normalization).","commonSituations":"Client computes endTime by subtracting instead of adding; passes startTime/endTime as date-only so the slot service sees them as equal midnight; timezone conversion flips the order; a date picker allowing the user to pick an end before the start.","solutions":["Ensure startTime is strictly before endTime and the window has positive duration when sent.","Send full ISO-8601 instants (with Z) for both params, not bare dates.","Validate client-side that endTime is in the future and after startTime before firing the request."],"exampleFix":"// before\napi.get('/slots/2024-04-15', { startTime: end, endTime: start }); // swapped\n// after\nconst start = new Date();\nconst end = new Date(start.getTime() + 7 * 86400000);\napi.get('/slots/2024-04-15', { startTime: start.toISOString(), endTime: end.toISOString() });","handlingStrategy":"validation","validationCode":"function buildSlotsQuery(startTime: Date, endTime: Date) {\n  if (!(startTime.getTime() < endTime.getTime()))\n    throw new Error('startTime must be strictly before endTime');\n  if (endTime.getTime() <= Date.now())\n    throw new Error('endTime must be in the future');\n  return { startTime: startTime.toISOString(), endTime: endTime.toISOString() };\n}","typeGuard":"const isValidSlotRange = (start: Date, end: Date): boolean =>\n  start.getTime() < end.getTime() && end.getTime() > Date.now();","tryCatchPattern":null,"preventionTips":["Always send full ISO instants with the Z suffix, not bare dates.","Disable the slots request until start < end and end is in the future.","Beware timezone normalization that can collapse a window to zero duration."],"tags":["slots","time-range","query-validation","nestjs","api-v2"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}