{"record":{"id":"d73f2abb7231784b","repo":"calcom/cal.diy","slug":"invalid-key-seconds-expected-value-between-0-a","errorCode":null,"errorMessage":"Invalid ${key} seconds. Expected value between 0 and 59","messagePattern":"Invalid (.+?) seconds\\. Expected value between 0 and 59","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"apps/api/v2/src/platform/schedules/schedules_2024_04_15/inputs/create-availability.input.ts","lineNumber":54,"sourceCode":"  const parts = timePart.split(\":\");\n\n  if (parts.length !== 3) {\n    throw new BadRequestException(\n      `Invalid time format. Expected format(ISO8061): 2025-0412T13:17:56.324Z. Received: ${value}`\n    );\n  }\n  const [hours, minutes, seconds] = parts.map(Number);\n\n  if (hours < 0 || hours > 23) {\n    throw new BadRequestException(`Invalid ${key} hours. Expected value between 0 and 23`);\n  }\n\n  if (minutes < 0 || minutes > 59) {\n    throw new BadRequestException(`Invalid ${key} minutes. Expected value between 0 and 59`);\n  }\n\n  if (seconds < 0 || seconds > 59) {\n    throw new BadRequestException(`Invalid ${key} seconds. Expected value between 0 and 59`);\n  }\n\n  return new Date(new Date().setUTCHours(hours, minutes, seconds, 0));\n}\n","sourceCodeStart":36,"sourceCodeEnd":59,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/apps/api/v2/src/platform/schedules/schedules_2024_04_15/inputs/create-availability.input.ts#L36-L59","documentation":"Thrown by transformStringToDate when the parsed seconds value falls outside the valid 0–59 range. Extracted from the third colon-separated segment and converted via Number(). The ${key} identifies the field (startTime or endTime). This is the last validation before the function constructs and returns a Date via setUTCHours.","triggerScenarios":"Sending a time with seconds = 60 (e.g., '09:00:60'); sending negative seconds; leap second representation '09:00:60' which the system doesn't accept.","commonSituations":"Client-side time arithmetic produces an out-of-range seconds value; manual string construction; rounding errors from floating-point time calculations.","solutions":["Ensure seconds in the time string are between 0 and 59.","Use toISOString() on a Date object to guarantee valid second values.","Set seconds to '00' if your use case doesn't require second-level precision."],"exampleFix":"// before\n\"startTime\": \"2025-04-12T09:00:60.000Z\"\n// after\n\"startTime\": new Date(2025, 3, 12, 9, 0, 0).toISOString()","handlingStrategy":"validation","validationCode":"function validateSeconds(isoString: string, fieldName: string): void {\n  const timePart = isoString.split('T')[1]?.split('.')[0];\n  const seconds = Number(timePart?.split(':')[2]);\n  if (isNaN(seconds) || seconds < 0 || seconds > 59) {\n    throw new Error(`${fieldName}: seconds must be 0-59, got ${seconds}`);\n  }\n}\n\nvalidateSeconds(item.startTime, 'startTime');","typeGuard":"function hasValidSeconds(isoString: string): boolean {\n  const timePart = isoString.split('T')[1]?.split('.')[0];\n  if (!timePart) return false;\n  const seconds = Number(timePart.split(':')[2]);\n  return !isNaN(seconds) && seconds >= 0 && seconds <= 59;\n}","tryCatchPattern":null,"preventionTips":["Use Date objects and toISOString() to produce valid second values automatically.","Set seconds to 00 explicitly if second-level precision isn't needed.","Validate the seconds component client-side before sending the request."],"tags":["validation","time","range-check","input","schedules"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}