calcom/cal.diy · warning · BadRequestException

Invalid ${key} seconds. Expected value between 0 and 59

Error message

Invalid ${key} seconds. Expected value between 0 and 59

What it means

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.

Source

Thrown at apps/api/v2/src/platform/schedules/schedules_2024_04_15/inputs/create-availability.input.ts:54

  const parts = timePart.split(":");

  if (parts.length !== 3) {
    throw new BadRequestException(
      `Invalid time format. Expected format(ISO8061): 2025-0412T13:17:56.324Z. Received: ${value}`
    );
  }
  const [hours, minutes, seconds] = parts.map(Number);

  if (hours < 0 || hours > 23) {
    throw new BadRequestException(`Invalid ${key} hours. Expected value between 0 and 23`);
  }

  if (minutes < 0 || minutes > 59) {
    throw new BadRequestException(`Invalid ${key} minutes. Expected value between 0 and 59`);
  }

  if (seconds < 0 || seconds > 59) {
    throw new BadRequestException(`Invalid ${key} seconds. Expected value between 0 and 59`);
  }

  return new Date(new Date().setUTCHours(hours, minutes, seconds, 0));
}

View on GitHub (pinned to 176037d0af)

Solutions

  1. Ensure seconds in the time string are between 0 and 59.
  2. Use toISOString() on a Date object to guarantee valid second values.
  3. Set seconds to '00' if your use case doesn't require second-level precision.

Example fix

// before
"startTime": "2025-04-12T09:00:60.000Z"
// after
"startTime": new Date(2025, 3, 12, 9, 0, 0).toISOString()
Defensive patterns

Strategy: validation

Validate before calling

function validateSeconds(isoString: string, fieldName: string): void {
  const timePart = isoString.split('T')[1]?.split('.')[0];
  const seconds = Number(timePart?.split(':')[2]);
  if (isNaN(seconds) || seconds < 0 || seconds > 59) {
    throw new Error(`${fieldName}: seconds must be 0-59, got ${seconds}`);
  }
}

validateSeconds(item.startTime, 'startTime');

Type guard

function hasValidSeconds(isoString: string): boolean {
  const timePart = isoString.split('T')[1]?.split('.')[0];
  if (!timePart) return false;
  const seconds = Number(timePart.split(':')[2]);
  return !isNaN(seconds) && seconds >= 0 && seconds <= 59;
}

Prevention

When it happens

Trigger: 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.

Common situations: Client-side time arithmetic produces an out-of-range seconds value; manual string construction; rounding errors from floating-point time calculations.

Related errors


AI-assisted analysis of calcom/cal.diy@176037d0af (2026-08-12). Data as JSON: /api/errors/d73f2abb7231784b. Report an issue: GitHub.